Global Araç
Tower Of Hanoi
Hamle
0
Optimal
15
Tüm diskleri sol çubuktan sağa taşıyın. Yalnızca küçük bir diski büyük olanın üzerine koyabilirsiniz. Seçmek için bir çubuğa tıklayın; taşımak için başka birine tıklayın. Optimal çözüm 2ⁿ−1 hamledir; 4 disk için 15.
The classic Tower of Hanoi puzzle. Three pegs, n disks stacked on the left peg in size order (largest at the bottom). Goal: move all disks to the right peg. Rule: you can only move one disk at a time, and you can never place a larger disk on top of a smaller one. Pick 3 to 8 disks for varying difficulty (3 is trivial; 8 is genuinely time-consuming).
The puzzle was invented by French mathematician Édouard Lucas in 1883, marketed as “Tour d’Hanoï” with a fictional legend about monks at a temple in Hanoi moving 64 golden disks (which, at one move per second, would take 2^64 − 1 ≈ 585 billion years — roughly 40× the age of the universe — implying the world ends when they finish). The puzzle became wildly popular and remained a recreational and educational favorite ever since.
The optimal solution requires exactly 2^n − 1 moves:
- 3 disks: 7 moves
- 4 disks: 15 moves
- 5 disks: 31 moves
- 6 disks: 63 moves
- 7 disks: 127 moves
- 8 disks: 255 moves
- 10 disks: 1,023 moves
- 20 disks: ~1 million moves
- 64 disks: ~18 quintillion moves (~585 billion years at 1 move/second)
The recursive solution is the canonical Computer Science 101 introduction to recursion: to move n disks from peg A to peg C using peg B as auxiliary, (1) recursively move n-1 disks from A to B; (2) move disk n from A to C; (3) recursively move n-1 disks from B to C. Three lines of pseudocode produce the optimal solution. It’s used in every introductory algorithms course as the textbook example of how recursion can elegantly solve problems that would be painful to solve iteratively.
Nasıl Kullanılır
- Pick the number of disks (3-8). 3 = trivial intro; 5 = good practice; 8 = genuinely takes 5-15 minutes.
- Click any peg to pick up the top disk on that peg. The disk highlights as 'selected'.
- Click another peg to drop the selected disk there. If the move violates the size-order rule (larger on smaller), it's rejected.
- Continue until all disks are on the right peg.
- The tool tracks your move count. Optimal is 2^n − 1; if you exceed that, you took some unnecessary moves. Try the recursive strategy: to move n disks from left to right, first move n-1 disks to middle, move the largest to right, then move n-1 from middle to right.
Ne Zaman Kullanılır
- Learning or teaching recursion — the Tower of Hanoi solution is canonical.
- Quick brain workout (3-15 minutes for 5-7 disks).
- Algorithm visualization for kids or new CS students — abstract concepts become concrete with the puzzle.
- Demonstrating exponential growth (each added disk doubles the time) for math / probability lessons.
Ne Zaman Kullanılmaz
- When you want a longer game — 8 disks max in this version, takes maybe 15-20 minutes for new solvers.
- If you find precision-task puzzles frustrating — accidental wrong-peg clicks reset progress.
- Multiplayer — single-player only; can't be raced or co-oped meaningfully.
Yaygın Kullanım Senaryoları
- Verifying a number or output before passing it on
- Quick use during a typical workday
- Pre-decision sanity-check on inputs and outputs
- Educational use — demonstrating the underlying concept
Sık Sorulan Sorular
What's the optimal move count?
2^n − 1 for n disks. So 3 disks = 7 moves, 4 = 15, 5 = 31, 8 = 255, 10 = 1023. The recursive solution is famous in computer science as THE canonical recursion example. Once you internalize 'move n-1 to middle, move the bottom to right, move n-1 to right', the puzzle becomes mechanical.
What's the legend?
Lucas's marketing invention: monks at a temple in Hanoi (or Benares, in some versions) move 64 golden disks between three diamond needles, following the same rules. They've been at it since the dawn of time. When they finish, the world ends. At one move per second optimally: 2^64 − 1 ≈ 18.4 quintillion seconds ≈ 585 billion years — about 40× the current age of the universe. The world is safe.
Why is this the canonical recursion example?
Because the recursive solution is so much cleaner than the iterative one. To move n disks from A to C: (1) recursively move n-1 disks from A to B; (2) move disk n from A to C; (3) recursively move n-1 from B to C. Three lines, full solution. The iterative version requires careful state tracking and is much longer. CS students see this and 'get' recursion as a problem-solving paradigm.
Is there an iterative solution?
Yes — the iterative algorithm tracks parity (odd vs even disk count) and applies a rotation rule: smallest disk moves in a fixed direction (left or right depending on parity), other moves are forced. Cleaner than naive iteration but harder to derive than the recursive version. Both have the same 2^n − 1 move count.
How long would a 64-disk puzzle take?
At 1 move per second: 2^64 − 1 ≈ 1.8 × 10^19 seconds ≈ 585 billion years. Even at 1 BILLION moves per second (using a fast computer): still ~585 years. The puzzle gets practically intractable beyond ~50 disks. This is the entry-level demonstration of exponential growth — adding ONE disk doubles the work.
Can I do larger than 8 disks?
Not in this UI version. 8 disks is 255 optimal moves which is already 5-15 minutes of clicking for a casual player. 10+ disks would test your patience and the limits of the UI. For programmatic exploration, write the recursive solver in your favorite language — it's a 5-line function.