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
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
You could either count the zeros at the end of a binary counter, or constrain alternating disks to move in opposite directions.
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
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).
ASKER
Can anybody give me some sample code.... please.... I'm too busy to figure out... still got project to do...
ASKER
I know it's sound lazy... but I really don't have extra time left...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you Alex...