Sorry if this is a duplicate - I think the original got caught because I
sent it from the wrong address .... you can save 2 lines by using a
function rather than a handler (watch for line wraps)
on mouseUp
ask "How many disks are there?"
put tower (it , "A", "B" , "C") into field 1
end mouseUp
function tower N, start, destination, spare
if N = 0 then return ""
return tower (N - 1, start, spare, destination) & "Move " & N & "
from "& start & " to "& destination & cr & tower (N - 1, spare,
destination, start)
end tower
-- Alex
On 19/07/2012 11:59, Jim Hurley wrote:
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
_______________________________________________
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