You are given the classic Towers of Hanoi problem:
There are three posts and circular disks of distinct sizes ( denotes the smallest disk, the largest). The disks start stacked on post , and the goal is to move the entire stack to post . At each step, you may move one disk from the top of one post onto another post, but you may never place a larger disk on top of a smaller one. The posts are named , , and .
A well-known recursive solution to this problem is as follows:
move(num_disks, from_post, spare_post, to_post)
if (num_disks == 0)
return
move(num_disks--1, from_post, to_post, spare_post)
print("Move disk ", num_disks, " from ", from_post, " to ", to_post)
move(num_disks--1, spare_post, from_post, to_post)Given and , determine the -th move performed by this recursion.
Each input line contains two integers and . Input ends with a line containing two zeros. All inputs are valid. and are positive integers, with k < 2^n and n \leq 60.
For each case, output the -th move in the following format:
Case :
where is the test case number (starting from 1), is the disk number, is the source post, and is the destination post. Use a single space to separate the parts; do not print trailing spaces.
Example 1