Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Fractran executor
(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)))
(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)
(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