Spyke
linux_gaming·Linux Gamingbychristos

Terminal Tower of Hanoi, in Bash

cross-posted from: https://lemmy.world/post/47988648

https://gitlab.com/christosangel/hanoi

Hanoi is a simple terminal version of the known classical game Tower of Hanoi, written in Bash.

During the game, the user can move left and right, pick disks and drop them in other stacks.

The aim is to move all the disks from the ORIGIN pile to the DESTINATION pile, in as little moves as possible

View original on lemmy.world

Didn't know it had a name but that makes sense... I remember playing a minigame puzzle like that as a kid in KOTOR

7
fedia.io

If I correctly remember the minimum number of moves required to get all the disks from one tower to another, 10 layers is going to be a slog.

7
christosreply
lemmy.world

The minimum number of moves required to solve a Tower of Hanoi puzzle is 2**n − 1, where n is the number of disks. 1023 for 10 disks, 5011 for 9 disks (updated max disks in the game). Recursion to the max.

7
besmttreply
lemmy.world

1023 for 10 disks, 5011 for 9 disks

More moves for less disks?

4
christosreply
lemmy.world

Yup, this is fat finger mathematics. The correct number is 511, somehow zero got in the way.

8

I have just updated the script, now up to 13 disks available (optimal moves: 8191).

It will take a while to solve it...

2
lornosajreply
lemmy.world

I might be just tired, but it took me a stupidly long second to get that minimum number of moves formula - not to nitpick, but isn’t that exp. usually written as 2^n - 1 ?

1
christosreply
lemmy.world

I don't know, it is not often that I use exp in writing, however:

$ echo $((2**9-1))
3

You reached the end

Terminal Tower of Hanoi, in Bash | Spyke