A tower of n disks (disk 1 smallest, disk n largest) starts stacked on spire 0 and is relocated to spire 2 using spire 1 as spare, via the standard optimal 2^n - 1-move recursion (relocate top n-1 to the spare, move disk n, relocate the n-1 onto disk n).
After exactly k moves have been performed (0 <= k <= 2^n - 1), report the contents of each spire. The intended approach determines each disk's spire recursively without replaying all k moves one by one.
A single line with two integers: n k.
Exactly three lines, one per spire in the order spire 0, spire 1, spire 2. Each line lists that spire's disks from bottom to top (largest to smallest), space-separated. Print an empty line for a spire that holds no disks.
Example 1
Input
3 0
Expected
3 2 1
Explanation
No moves have happened, so all three disks 3, 2, 1 remain stacked on spire 0 and the other spires are empty.
Example 2
Input
3 4
Expected
2 1 3
Explanation
After 4 of the 7 moves, disk 3 has just moved to spire 2, disks 2 and 1 sit on spire 1, and spire 0 is empty.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →