Hanoi Tower programming challenge...
Jim Hurley
jhurley0305 at sbcglobal.net
Thu Jul 19 06:59:18 EDT 2012
>
> Message: 17
> Date: Wed, 18 Jul 2012 22:22:59 -0400
> From: Colin Holgate <coiin at verizon.net>
> To: How to use LiveCode <use-livecode at lists.runrev.com>
> Subject: Hanoi Tower programming challenge...
> Message-ID: <65C1B2BF-D4A1-460F-A362-AFDEDCCEC1E2 at verizon.net>
> Content-Type: text/plain; charset=us-ascii
>
> In another tool's email list there is a thread going on about how it was possible to solve the Hanoi Tower puzzle in under 20 lines. Without getting too crazy it was possible to solve the problem in 16 lines of code. With a little craziness it could be done in 13 lines.
>
> Assuming you have any idea what I'm talking about, how many lines of LiveCode would you need to print out all the steps of solving a Hanoi Tower game?
>
Colin,
How about this? I think this is the classic recursive solution.
Jim Hurley
on mouseUp
ask "How many disks are there?"
tower it , "A", "B" , "C"
end mouseUp
on tower N, start, destination, spare
if N = 0 then exit tower
tower N - 1, start, spare, destination
put "Move " & N & " from "& start & " to "& destination & cr after field 1
tower N - 1, spare, destination, start
end tower
More information about the use-livecode
mailing list