> 
> Message: 17
> Date: Wed, 18 Jul 2012 22:22:59 -0400
> From: Colin Holgate <co...@verizon.net>
> To: How to use LiveCode <use-livecode@lists.runrev.com>
> Subject: Hanoi Tower programming challenge...
> Message-ID: <65c1b2bf-d4a1-460f-a362-afdedccec...@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
_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to