Last active
April 19, 2016 13:10
-
-
Save MarkArts/479c7efd8811d8850b36da7868fc014f to your computer and use it in GitHub Desktop.
Lisp Fib and Hanoi fun for Structure and Interpretation of computer languages course
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun fib (n) | |
(loop repeat n | |
with p = 0 with q = 1 | |
do(psetq p q | |
q (+ p q)) | |
collect q | |
) | |
) | |
(print (last (fib 1000))) | |
(defun printMove (from to) | |
(print (concatenate `string "Move from: " (write-to-string from) " To: " (write-to-string to) )) | |
) | |
(defun move (amount from to spare) | |
(cond | |
((= 1 amount) | |
(printMove from to) | |
) | |
(T | |
(move (1- amount) from spare to) | |
(move 1 from to spare) | |
(move (1- amount) spare to from) | |
) | |
) | |
) | |
(move 3 1 2 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment