Thursday 3 November 2011

Puzzle-17 (NASSCOM- Sample Problems)

In the island of Hanoi is trapped a princess. To rescue her, the price has to transfer a set of rings numbered 1 to 7 from tower A to tower C. The rings are stacked one over the other in an order, with 1 at the top and 6 at the bottom, and have to be stacked in the same fashion on tower C. The prince can move only one ring at a time, and can store the rings in a stack temporarily, in another tower B. Minimum how many moves of rings between the towers, will it take the prince, to arrange the rings in tower C?
(1) 13              (2) 127                        (3) 14              (4) 129
Solution follows here:
Solution:


“The rings are stacked one over the other in an order, with 1 at the top and 6 at the bottom”
Out of all 7 rings, top 6 rings can be stacked one after the other on tower B in 6 moves (on tower-B, those 6 rings stacked in reverse order).
The bottom most one ie., ring-6 can be directly moved from tower-A to tower-C in 1 move (on tower-C it occupies the bottom most place).
Now all the 6 rings on tower-B can be stacked one after the other on tower C in 6 moves (on tower-C, those 6 rings stacked in reverse of reverse ie., correct order now).



Summary:
Step-1: Tower-A to Tower-B => 6 moves
Step-2: Tower-A to Tower-C => 1 move
Step-3: Tower-B to Tower-C => 6 moves
Total moves = 6+1+6 = 13
Answer (1)

No comments:

Post a Comment