|
From: Luigi S. <gi...@li...> - 2002-01-23 16:26:04
|
Some time ago I was asked to solve this: Towers of Hanoi: given a stack of disks, threaded onto one peg and arranged from bottom to top in decreasing size, move the stack to a second peg under the following two conditions: - one disk is moved at a time - at no time may a larger disk be placed above a smaller one A third peg is available for temporarily holding disks. If your problem is similar to the one above, one solution could be using "induction" as suggested by Mr. Silverman: if you have one disk, move it and you are over; when there is more than a disk, say n, move the n - 1 small ones on the temporary peg, then place the n-th (the biggest) on the destination peg, finally move the small ones from the temporary peg to the destination one. I've attached an archive with two directories, one has my very simple (original) C solution and the other has a C++ version of it. Let me know if you find them of some help. At 01:16 23/01/02 +0000, chromatonus 712 wrote: >Anyone has a simple source code for this (any number of disks)? Thank you! -- Luigi gi...@li... |