---
title: "\"汉诺塔\"问题"
author: "desert3"
date: "2011-10-17T14:09:57Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2011-10-17T14:09:57Z"
id: 1198389
url: "https://desert3.iteye.com/blog/1198389"
---

\[code="js"] // "汉诺塔"难题：塔的设备包括三根柱子和一套直径各不相同的空心圆盘。开始时源柱子上的所有圆盘都按照较小的 // 圆盘放在较大的圆盘上的顺序堆叠。目标是通过每次移动一个圆盘到另一根柱子，最终将一堆圆盘移动到目标柱子 // 上，过程中不可以将大的圆盘放置在较小的圆盘之上。 var hanoi = function (disc, src, aux, dst) { if (disc &gt; 0) { hanoi(disc - 1, src, dst, aux); document.writeln('Move disc ' + disc + ' from ' + src + ' to ' + dst + '  
'); hanoi(disc - 1, aux, src, dst); } } hanoi(3, 'Src', 'Aux', 'Dst'); \[/code] 结果： \[code="html"] Move disc 1 from Src to Dst Move disc 2 from Src to Aux Move disc 1 from Dst to Aux Move disc 3 from Src to Dst Move disc 1 from Aux to Src Move disc 2 from Aux to Dst Move disc 1 from Src to Dst \[/code]