📄 towershanoi.html
字号:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD W3 HTML 2.0//EN">
<HTML lang="en-US">
<HEAD>
<TITLE>towers of Hanoi</TITLE>
<META name="description"
content="Definition of towers of Hanoi,
possibly with links to more information and implementations.">
<META name="keywords" content="towers of Hanoi">
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<H1>towers of Hanoi</H1>
<P>
(classic problem)
<P>
<strong>Definition:</strong>
Given three posts (towers) and <em>n</em> disks of decreasing sizes, move the disks from one post to another one at a time without putting a larger disk on a smaller one. The minimum is 2<sup>n</sup>-1 moves. The "ancient legend" was written in 1884.
<P><em>Note:
A solution using <a href="recursion.html" tppabs="http://hissa.nist.gov/dads/HTML/recursion.html"><em>recursion</em></a> is to move <em>n</em> disks from post A to post B is 1) recursively move the top <em>n-1</em> disks from post A to C, 2) move the n<sup>th</sup> disk from A to B, and 3) recursively move the <em>n-1</em> disks from C to B. A solution using <a href="iteration.html" tppabs="http://hissa.nist.gov/dads/HTML/iteration.html"><em>iteration</em></a> is on odd-numbered moves, move the smallest disk clockwise. On even-numbered moves, make the single other move which is possible.</em>
<P>Author: <a href="terms.html#authorPEB" tppabs="http://hissa.nist.gov/dads/terms.html#authorPEB">PEB</a>
<H2>Implementation</H2>
<A HREF="javascript:if(confirm('http://www.nist.gov/cgi-bin/exit_nist.cgi?url=http://javascript.internet.com/games/hanoi.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.nist.gov/cgi-bin/exit_nist.cgi?url=http://javascript.internet.com/games/hanoi.html'" tppabs="http://www.nist.gov/cgi-bin/exit_nist.cgi?url=http://javascript.internet.com/games/hanoi.html">(JavaScript)</A>, <A HREF="javascript:if(confirm('http://www.nist.gov/cgi-bin/exit_nist.cgi?url=http://mars.superlink.net/rzeitel/rzhanoi.java \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.nist.gov/cgi-bin/exit_nist.cgi?url=http://mars.superlink.net/rzeitel/rzhanoi.java'" tppabs="http://www.nist.gov/cgi-bin/exit_nist.cgi?url=http://mars.superlink.net/rzeitel/rzhanoi.java">(Java)</A>, <A HREF="javascript:if(confirm('http://www.nist.gov/cgi-bin/exit_nist.cgi?url=http://kumo.swcp.com/imagine1/ex_hanoi.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.nist.gov/cgi-bin/exit_nist.cgi?url=http://kumo.swcp.com/imagine1/ex_hanoi.html'" tppabs="http://www.nist.gov/cgi-bin/exit_nist.cgi?url=http://kumo.swcp.com/imagine1/ex_hanoi.html">(F)</A>
<H2>More information</H2>
The <A HREF="javascript:if(confirm('http://www.nist.gov/cgi-bin/exit_nist.cgi?url=http://alabanza.com/kabacoff/Inter-Links/puzzles.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.nist.gov/cgi-bin/exit_nist.cgi?url=http://alabanza.com/kabacoff/Inter-Links/puzzles.html'" tppabs="http://www.nist.gov/cgi-bin/exit_nist.cgi?url=http://alabanza.com/kabacoff/Inter-Links/puzzles.html">Puzzle Archive</A> gives background and <A HREF="javascript:if(confirm('http://www.nist.gov/cgi-bin/exit_nist.cgi?url=http://alabanza.com/kabacoff/Inter-Links/fun/puzzles/induction \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.nist.gov/cgi-bin/exit_nist.cgi?url=http://alabanza.com/kabacoff/Inter-Links/fun/puzzles/induction'" tppabs="http://www.nist.gov/cgi-bin/exit_nist.cgi?url=http://alabanza.com/kabacoff/Inter-Links/fun/puzzles/induction">a recursive and an iterative solution</A>
<hr>
Go to the
<A HREF="terms.html" tppabs="http://hissa.nist.gov/dads/terms.html">Algorithms, Data Structures, and Problems</A>
home page.
<hr>
If you have suggestions, corrections, or comments, please get in touch
with
<a href="javascript:if(confirm('http://hissa.nist.gov/~black/black.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://hissa.nist.gov/~black/black.html'" tppabs="http://hissa.nist.gov/~black/black.html">Paul E. Black</a>
(<a href="mailto:paul.black@nist.gov">paul.black@nist.gov</a>).
<p>
Entry modified Thu Oct 7 10:11:18 1999.<BR>
HTML page formatted Wed Dec 22 09:36:44 1999.
<P>
This page's URL is
<A href="towershanoi.html" tppabs="http://hissa.nist.gov/dads/HTML/towershanoi.html">http://hissa.nist.gov/dads/HTML/towershanoi.html</A>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -