Courses‎ > ‎Intro to CS - Full Year‎ > ‎Spring‎ > ‎Dyrland-Weaver‎ > ‎Work‎ > ‎

Work 26: 4/9

posted Apr 9, 2019, 12:37 PM by JonAlf Dyrland-Weaver
Write a function that will print out (no returning) the steps to solve the towers of hanoi.
  • Use the following function header: hanoi(n, start, end, temp)
    • n: number of disks
    • start: starting pole to move disks off
    • end: goal pole for all the disks
    • temp: pole to be used to store disks temporarily
    • start, end and temp should be 0, 1 or 2
  • The starting call should look like this:
    • hanoi(4, 0, 2, 1)
  • The output should be in the format pole to pole
    • example:
      • hanoi(2, 0, 2, 1)
        • 0 to 1
        • 0 to 2
        • 1 to 2
  • You can test your output by copying it into the "Move List" text box here: http://homer.stuy.edu/~dw/hanoi/
    • Click Solve and it will play out your moves. Don't forget to initialize with the correct number of disks.
Submit this as hanoi
Comments