Hanoi Tower programming challenge...

Björnke von Gierke bvg at mac.com
Thu Jul 19 07:50:15 EDT 2012


Showing stuff on screen in LC is always surprisingly code intensive, So text only approaches probably win here. Here's a C code that I transcribed into LC, because I'm lazy and everyone knows that c is the laziest language of them all ;)

Also I'm amused by all the old geezer complaining that the challenge is not worth much, and therefore no one should try to do it xD

on mouseUp
   put "" into field 1
   doTheTower 6,"pole 1", "pole 2", "pole 3"
end mouseUp

on doTheTower thePiece, p1, p2, p3
   if thePiece > 1 then doTheTower thePiece-1, p1, p3, p2
   put "move piece" && thePiece && "from" && p1 && "to" && p2 & return after field 1
   if thePiece > 1 then doTheTower thePiece-1, p3, p2, p1
end doTheTower

Note that this is an artificially shortened version, which actually looks like this:

on doTheTower thePiece, p1, p2, p3
   if thePiece = 1 then 
      put  "move piece " && thePiece && "from" && p1 && "to" && p2 & return after field 1
   else
      doTheTower thePiece-1, p1, p3, p2
      put  "move piece " && thePiece && "from" && p1 && "to" && p2 & return after field 1
      doTheTower thePiece-1, p3, p2, p1
   end if
end doTheTower

On 19.07.2012, at 04:22, Colin Holgate wrote:

> 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?
> 
> 
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


-- 

Use an alternative Dictionary viewer:
http://bjoernke.com/bvgdocu/

Chat with other RunRev developers:
http://bjoernke.com/chatrev/








More information about the Use-livecode mailing list