Created
June 11, 2016 18:55
-
-
Save malisper/3a8594c96cea47471565be8d08be25f9 to your computer and use it in GitHub Desktop.
Fractran executor
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 multiple (a b) | |
"Is A a multiple of B?" | |
(= (mod a b) 0)) | |
(defun next-fraction (n fractions) | |
"Returns the next value of F in the Fractran program." | |
(find-if (lambda (f) | |
(integerp (* n f))) | |
fractions)) | |
(defun print-fractran-alphabet (n chars) | |
"After moving to state N, print all of the necessary characters." | |
(loop for (char . number) in chars | |
when (multiple n number) | |
do (princ char))) | |
(defun run-fractran (fractions alphabet &optional (n 2)) | |
"Run the given Fractran program. ALPHABET is an alist of characters to numbers | |
representing the alphabet." | |
(let ((f (next-fraction n fractions))) | |
(if (null f) | |
nil | |
(let ((next (* n f))) | |
(print-fractran-alphabet next alphabet) | |
(run-fractran fractions alphabet next))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment