Last active
December 22, 2015 22:49
-
-
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)
This file contains hidden or 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
(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*)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.