Consider binary strings (reading from left to right) starting with a '1' as ponds of lily pads. A '1' signifies a frog sitting on the lily pad, and a '0' represents an empty lily pad.
Here, we see a pond with 7 lily pads on which 4 frogs are sitting:
1101001
The frogs want to all party together. This means that, ultimately, they all want to sit on a single lily pad. However, there are rules as to how to achieve this:
- All of the frogs on a single lily pad jump at once.
- If there are k frogs jumping they jump k spaces to the right or left. (they must all jump in the same direction.)
- Frogs are not allowed to jump onto an empty lily pad.
Examples
1
11 -> 02
111 -> 021 -> 030
1011 -> 1020 -> 3000
1101001 -> 0201001 -> 0003001 -> 0000004
10001111 -> 10002011 -> 10002020 -> 10004000 -> 50000000
10110111 -> 10020111 -> 10000311 -> 10000302 -> 10000500 -> 60000000
Challenge
Given n, show all ponds as binary strings, which allow the n frogs to gather to a party. But disregard ponds, which are only a left-right reversal of another one. The output can be given as a comma-separated list or line by line.
For example, for 4 frogs, the output is
[1111, 11101, 11011, 111001, 1101001]
These sequences of jumps lead to the party:
1111 -> 0211 -> 0013 -> 0004
11101 -> 02101 -> 03001 -> 00004
11011 -> 02011 -> 02020 -> 04000
111001 -> 201001 -> 003001 -> 000004
1101001 -> 0201001 -> 0003001 -> 0000004
As a test case show the 12 solutions for 5 frogs. The order is not fixed!
11111
111011
111101
1101011
1110011
1111001
11010011
11011001
11110001
111010001
1110010001
11010010001
This is code-golf, so each language's shortest code in bytes wins.
Credits
Gordon Hamilton, Jumping Frogs
Gordon Hamilton and Brady Haran, Frog Jumping, Numberphile video.
Glen Whitney, OEIS A378004 (counting the number of solutions).
1011011001 -> 1002002001 -> 1002011001 -> 0002002002 -> 0000003003 -> 0000000006
? I don't think it makes a difference for the case where n=4, and none of the example show frogs from different lily pads jumping simultaneously. \$\endgroup\$50310001 -> 30510001 -> 30010006 -> 00040006 -> 0000000X
permitted? The question should really state this, because as worded now it entails that both of these are permissible moves. \$\endgroup\$1110101 -> 0210101 -> 0300101 -> 0000401 -> 0000203 -> 0000005
? All the more reason that you should really give n=5 as a real test case if you want it as a "test case"...) \$\endgroup\$