You are browsing as a guest. Sign up (or log in) to start making projects!

Hanoi

  • 1 Devlogs
  • 3 Total hours

A utility to solve the Tower of Hanoi.

Open comments for this post

2h 32m 59s logged

I’m writing a CLI tool to solve the Tower of Hanoi puzzle/game in Swift.
I finished up writing classes for the Game, Stacks, and Pieces.
Now I’m in the middle of writing the algorithm to solve the game. It
seems to break when the recursive Stack.move method’s counter (the
variable that’s decremented and passed to the recursive function/method)
gets to 1.

The logs should start with

[[1, 2, 3, 4], [0], [0]]
[[2, 3, 4], [1], [0]]
[[3, 4], [1], [2]]
[[3, 4], [0], [1, 2]]
[[4], [3], [1, 2]]
[[1, 4], [3], [2]]
[[14], [2, 3], [0]]

and continue on.

Instead they say

[[1, 2, 3, 4], [], []]
[[2, 3, 4], [1], []]
[[3, 4], [], [1, 2]]
[[4], [1, 3], [2]]

and stop (see attached screenshot).

0
0
8

Delete project?

Are you sure you want to permanently delete this project? This action cannot be undone.

All devlogs, followers, and associated data will be removed.

Followers

Loading…