Challenge for Towers of Hanoi - Part 1


Above, you moved disks from Peg 1 to Peg 3, but in this challenge, you need to move 2 disks from any starting peg to any goal peg.

You will be given two numbers (from 1 to 3) as input - the starting peg, and the goal peg. Write a function that calculates how to move 2 disks from the starting peg to the goal peg. Print out the steps.

Output Format:
Print the peg to move from, an arrow "->", and the peg to move to. For example, to move from peg 1 to peg 3, print "1->3".

Print all the steps for a given case on its own line. Print a newline after each case.

Please sign in or sign up to submit answers.

Alternatively, you can try out Learneroo before signing up.

Contact Us
Sign in or email us at [email protected]