Advertisement
alcidesfp

num-roman.lisp

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