Advertisement
alcidesfp

num-roman.lisp

Jan 17th, 2012
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.03 KB | None | 0 0
  1. ;; -*- coding: utf-8; mode: common-lisp -*-
  2. ;; num-roman.lisp
  3.  
  4. (setq matriz-numerales
  5.       (make-array '(10 4)
  6.         :initial-contents '((""     ""     ""     "" )
  7.                             ("I"    "X"    "C"    "M")
  8.                             ("II"   "XX"   "CC"   "MM")
  9.                             ("III"  "XXX"  "CCC"  "MMM")
  10.                             ("IV"   "XL"   "CD"   "")
  11.                             ("V"    "L"    "D"    "")
  12.                             ("VI "  "LX"   "DC"   "")
  13.                             ("VII"  "LXX"  "DCC"  "")
  14.                             ("VIII" "LXXX" "DCCC" "")
  15.                             ("IX"   "XC"   "CM"   "")) ))
  16.  
  17. (defun num-roman (n)
  18.   (setq retval "")
  19.   (setq cad-num (reverse (princ-to-string n)))
  20.   (loop for pos from (- (length cad-num) 1) downto 0 do
  21.        (setq num (parse-integer (string (elt cad-num pos))))
  22.        (setq retval (concatenate 'string
  23.                                  retval
  24.                                  (aref matriz-numerales num pos))) )
  25.   retval )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement