Guest User

Untitled

a guest
Apr 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. ;;; One-liner
  2. (defun roman-to-dec (string)(let*((dict(pairlis '(#\I #\V #\X #\L #\C #\D #\M) '(1 5 10 50 100 500 1000)))(lookup(lambda(c)(cdr(assoc c dict)))))(reduce(lambda(x y)(let((l(funcall lookup y)))(- (+ x l)(* 2(rem x l)))))(coerce string 'list):initial-value 0)))
  3.  
  4. ;;; Formatted version
  5. (defun roman-to-dec(string)
  6. (let* ((dict (pairlis '(#\I #\V #\X #\L #\C #\D #\M)
  7. '(1 5 10 50 100 500 1000)))
  8. (lookup (lambda (c) (cdr (assoc c dict)))))
  9. (reduce (lambda (x y) (let ((l (funcall lookup y)))
  10. (- (+ x l) (* 2 (rem x l)))))
  11. (coerce string 'list)
  12. :initial-value 0)))
Add Comment
Please, Sign In to add comment