Skip to main content

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 disks
  • rod#: 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

Metadata

Release files for k-peg-hanoi 0.2.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for k-peg-hanoi 0.2.6
File Interpreter ABI Platform Actions
k_peg_hanoi-0.2.6-py3-none-any.whl Python 3 none any Details for k_peg_hanoi-0.2.6-py3-none-any.whl

Release files / k_peg_hanoi-0.2.6-py3-none-any.whl

Download URL k_peg_hanoi-0.2.6-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
360eb1007287f9dfda128956e01a95fdfb7a0cc4b8b1f36897a33df3718860e0
BLAKE2b-256 checksum
How to use checksums
2e8b93abb0b98fbb9a8764b20ea72efef7d2d6b6db321b7faba0e2f515feb913
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for k-peg-hanoi 0.2.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page