Play Tower of Hanoi with 3 to 8 discs, see the minimum move count, and watch the shortest solution play out step by step from wherever you are.
Moves 0
Minimum 15
Time 0:00
Best -
Pick up the top disc of a peg, then choose where to put it.
Last move No moves yet.
Click or tap a peg to pick up its top disc, then click the peg to drop it on. Click the same peg again to put it back. With the keyboard: left and right arrows move between pegs, Enter or Space picks up and drops, 1 to 3 choose a peg directly, Escape puts a disc back, U undoes. Move every disc to another peg, one at a time, never a larger disc onto a smaller one.
To move a tower of n discs, move the top n - 1 discs to the spare peg, move the largest disc, then move the n - 1 discs back on top of it. That makes the minimum for n discs 2 x (the minimum for n - 1) + 1, which is 2^n - 1: 7 moves for 3 discs, 255 for 8. Auto-solve uses the same idea from wherever you are: it works from the largest disc down, skips any disc that is already where it needs to be, and plays the shorter of the plans for the two other pegs. Auto-solved games are not counted in your best results. Undo takes a disc back, but the move still counts in your total.
As-is, no warranty. These apps are free under their listed license and run entirely in your browser. Use at your own risk — don't blame me if your PC catches fire, your dog runs away, or the math turns out wrong. Verify anything that actually matters. None of this is professional financial, medical, legal, or engineering advice.
Three pegs, and a stack of discs on the first one with the largest at the bottom. Move the whole stack to another peg, one disc at a time, and never put a larger disc on a smaller one.
Every disc has its own colour as well as its number, from the smallest to the largest: rose, orange, amber, lime, green, teal, sky and violet. The colour is only decoration, because the number printed on each disc says which one it is. The three pegs have a soft tint of their own (sky, violet and amber) so they are easy to tell apart. A peg you can legally drop onto gets a dashed, glowing edge, which is a shape cue as well as a colour. When you finish, the discs hop one after another and the result card turns green. With reduced motion switched on in your system settings the hop is skipped.
Beside your move count the page shows the minimum possible for that many discs. When you finish it says Perfect if you matched it, or how many moves over the minimum you were. Undo takes a disc back, but the move still counts in your total, so the number stays honest. The timer starts at your first move and pauses when the tab is hidden.
To move a tower of n discs you have to move the n - 1 discs above the largest one out of the way, move the largest, then move those n - 1 discs back on top. So the minimum for n discs is twice the minimum for n - 1, plus one. That gives 2^n - 1: 7 moves for 3 discs, 15 for 4, 31 for 5, and 255 for 8. Each extra disc doubles the work.
The tests check this instead of assuming it:
Two regularities fall out of the shortest solution, and they are tested as described below:
Auto-solve plays the shortest solution one move at a time with a short delay (a minimal one if your device asks for reduced motion). Stop hands control back to you at any point. It works from where you are, not only from the start: it takes the largest disc, and if it is already in place it ignores it, otherwise it clears everything smaller onto the spare peg, moves it, and rebuilds. It plays the shorter of the plans for the two other pegs. For 3 to 6 discs the tests compare this against exhaustive search from every one of the possible positions and the lengths match.
Games that used Auto-solve are marked as such and do not count toward your best results.
Nothing is uploaded and there is no account. Your best move count and best time for each disc count are saved in your browser’s local storage as small whole numbers inside a small JSON object, under one key, and only for games you solved yourself. Clearing site data removes them. The page address holds the number of discs, so you can link to a particular size.
Everything runs locally in your browser.
For informational purposes only. Not financial, medical, or legal advice. You are solely responsible for how you use these tools.