There are n places set around a circular table. Alice is sat on one of them. At each place, there's a cake. Alice eats her cake, but it doesn't taste very nice. Then the Mad Hatter comes in. He gives Alice a list of n-1 numbers, each between 1 and n-1. For each item i in the list, Alice has to move around i places and eat the cake there if there is one. However, Alice will be able to choose whether to move clockwise or anticlockwise for each item in the list. She doesn't like the cakes, so she is trying not to eat them.
Given an integer n, output all the possible lists the Mad Hatter could use to force Alice to eat all the cakes (represented as a tuple/list of tuples/lists of integers or some tuples/lists of integers separated by newlines). Note that it is possible for the Mad Hatter to force Alice to eat all the cakes if and only if n is a power of two, so you may assume that n is a power of two. Make your code as short as possible.
You may also take in x such that 2^x=n if that helps. For example, you may take in 2 instead of 4, 3 instead of 8, etc.
The order in which your program returns the possible lists does not matter.
Test Cases
1 -> [[]]
2 -> [[1]]
4 -> [[2, 1, 2], [2, 3, 2]]
8 -> [[4, 2, 4, 1, 4, 2, 4], [4, 2, 4, 1, 4, 6, 4], [4, 6, 4, 1, 4, 2, 4], [4, 6, 4, 1, 4, 6, 4], [4, 2, 4, 3, 4, 2, 4], [4, 2, 4, 5, 4, 2, 4], [4, 2, 4, 7, 4, 2, 4], [4, 2, 4, 3, 4, 6, 4], [4, 6, 4, 3, 4, 2, 4], [4, 2, 4, 5, 4, 6, 4], [4, 6, 4, 5, 4, 2, 4], [4, 2, 4, 7, 4, 6, 4], [4, 6, 4, 7, 4, 2, 4], [4, 6, 4, 3, 4, 6, 4], [4, 6, 4, 5, 4, 6, 4], [4, 6, 4, 7, 4, 6, 4]]
[]
instead of[[]]
forn = 1
? \$\endgroup\$[[]]
because the Mad Hatter's list has length 0. This means that[]
is the only possible list (which works since Alice eats the only cake she has before the Mad Hatter comes in), so[[]]
is the list of all lists that work. \$\endgroup\$