Link to home
Start Free TrialLog in
Avatar of suelow
suelow

asked on

Tower of Hanoi - LISP

Is there any expert out there know how to do the problem for tower of hanoi using LISP in a non-recursive manner ?
I have the solution for recursive one but I'm having problem to do the non-recursive code...  help ...

(defun towerofhanoi(a)
  ( move 'A 'B 'C a ))

(defun display ( from to )
  (princ "Move Disk From Peg ")
  (princ from)
  (princ " To Peg")
  (princ to)
 (format t "~%")
  nil)


(defun move ( from to via a )
  (cond ((equal a 1) (display from to ))
        (t (move from via to (- a 1))
           (display from to)
           (move via to from (- a 1)))))
TOWEROFHANOI
Avatar of ozo
ozo
Flag of United States of America image

You could either count the zeros at the end of a binary counter, or constrain alternating disks to move in opposite directions.
Avatar of suelow
suelow

ASKER

I'm sorry... can't really understand.
See http://obelix.ee.duth.gr/~apostolo/TowersOfHanoi/ for detailed discussion
recurcive/not recursive algoritms
and C-code (not List, but i hope, you
can easy convert to to List).
Alex
In my comment List->Lisp(of course).
Avatar of suelow

ASKER

Can anybody give me some sample code.... please.... I'm too busy to figure out... still got project to do...
Avatar of suelow

ASKER

I know it's sound lazy... but I really don't have extra time left...
ASKER CERTIFIED SOLUTION
Avatar of AlexVirochovsky
AlexVirochovsky

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of suelow

ASKER

Thank you Alex...