Tower of Hanoi (using k peg)
Solves the Tower of Hanoi with any number of rods (3 or more) in as few moves as possible. It shows each move on the command line, and also provides a Python function that returns the moves.
Install
pip install k-peg-hanoi
Usage (hanoi {disk#} {rod#})
disk#: number of disksrod#: number of rods, default 3--text: show moves as text instead of drawing the towers
See hanoi --help
$ hanoi 3 3
=
===
=====
0----------------
===
===== =
1----------------
===== === =
2----------------
=
===== ===
3----------------
=
=== =====
4----------------
= === =====
5----------------
===
= =====
6----------------
=
===
=====
7----------------
$ hanoi 3 4
=
===
=====
0----------------------
===
===== =
1----------------------
===== = ===
2----------------------
= === =====
3----------------------
===
= =====
4----------------------
=
===
=====
5----------------------
$ hanoi 4 4 --text
#1 disk 1 from 0 to 1
#2 disk 2 from 0 to 3
#3 disk 3 from 0 to 2
#4 disk 2 from 3 to 2
#5 disk 4 from 0 to 3
#6 disk 2 from 2 to 0
#7 disk 3 from 2 to 3
#8 disk 2 from 0 to 3
#9 disk 1 from 1 to 3