Skip to content

Instantly share code, notes, and snippets.

@johanlindberg
Last active December 22, 2015 22:49
Show Gist options
  • Save johanlindberg/6542465 to your computer and use it in GitHub Desktop.
Save johanlindberg/6542465 to your computer and use it in GitHub Desktop.
Half-finished, non working, code for the Roman Numerals kata (from lisp.se #2 meeting)
(defparameter *symbols* '("*" "*" "M" "D" "C" "L" "X" "V" "I"))
(defparameter *patterns* '((0)
(1 2)
(2 2 2)
(3 2 2 2)
(4 2 1)
(5 1)
(6 1 2)
(7 1 2 2)
(8 1 2 2 2)
(9 2 0)))
(defun output-symbols (i syms)
(let ((list (cdr (assoc i *patterns*))))
(dolist (x list)
(write-string (nth x syms)))))
(defun recurse (number divisor syms)
(unless (zerop divisor)
(multiple-value-bind (i n) (truncate number divisor)
(output-symbols i syms)
(recurse n (truncate divisor 10) (cddr syms)))))
(defun solve (n)
(recurse n 1000 *symbols*))
@johanlindberg
Copy link
Author

We had to abandon the meeting a bit early which unfortunately left the code in an unfinished state. The second revision is the code I modified in order to make it work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment