?
Solved

Tower of Hanoi - LISP

Posted on 1999-12-14
8
Medium Priority
?
2,531 Views
Last Modified: 2008-03-10
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
0
Comment
Question by:suelow
  • 4
  • 3
8 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 2282906
You could either count the zeros at the end of a binary counter, or constrain alternating disks to move in opposite directions.
0
 

Author Comment

by:suelow
ID: 2282953
I'm sorry... can't really understand.
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 2283793
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
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 2283798
In my comment List->Lisp(of course).
0
 

Author Comment

by:suelow
ID: 2286090
Can anybody give me some sample code.... please.... I'm too busy to figure out... still got project to do...
0
 

Author Comment

by:suelow
ID: 2286161
I know it's sound lazy... but I really don't have extra time left...
0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 300 total points
ID: 2292205
0
 

Author Comment

by:suelow
ID: 2297529
Thank you Alex...
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Suggested Courses

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question