Created
April 28, 2010 21:03
-
-
Save RTfXGaGeqSeItbMUgpFlekUs/382708 to your computer and use it in GitHub Desktop.
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 collatz (n) | |
(labels ((internal (n lst) | |
(cond | |
((= n 1) (cons n lst)) | |
((evenp n) (internal (/ n 2) (cons n lst))) | |
((oddp n) | |
(internal (+ (* 3 n) 1) (cons n lst)))))) | |
(internal n '()))) | |
(defun list-to-gv (lst) | |
(labels ((internal (lst lastn) | |
(cond ((equalp lst nil) lst) | |
(t | |
(if (equalp lastn nil) | |
nil | |
(format t "~d -> ~d;~%" (car lst) lastn)) | |
(internal (cdr lst) (car lst)))))) | |
(internal lst nil))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment