Sha256: 94d13aef30de65a7321ad4351d626b8ef28f3e42b517c1f7a56707bc30f2bd66

Contents?: true

Size: 946 Bytes

Versions: 395

Compression:

Stored size: 946 Bytes

Contents

;;; roman-numerals.el --- roman-numerals Exercise (exercism)

;;; Commentary:

;;; Code:


(defun to-roman (value)
  (let ((decode '(("M"  . 1000)
                  ("CM" . 900)
                  ("D"  . 500)
                  ("CD" . 400)
                  ("C"  . 100)
                  ("XC" .  90)
                  ("L"  .  50)
                  ("XL" .  40)
                  ("X"  .  10)
                  ("IX" .   9)
                  ("V"  .   5)
                  ("IV" .   4)
                  ("I"  .   1)))
        (roman nil))
    (if (> value 3000)
        (error "Value out of range"))
    (while (not (eq value 0))
      (let ((r (caar decode))
            (d (cdar decode)))
        (when (>= value d)
          (setq roman (append roman (make-list (/ value d) r)))
          (setq value (% value d)))
        (setq decode (cdr decode))))
    (apply 'concat roman)))


(provide 'roman-numerals)
;;; roman-numerals.el ends here

Version data entries

395 entries across 395 versions & 1 rubygems

Version Path
trackler-2.2.1.119 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.118 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.117 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.116 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.115 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.114 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.113 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.111 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.110 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.109 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.108 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.107 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.106 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.105 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.104 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.103 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.102 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.101 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.100 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.99 tracks/elisp/exercises/roman-numerals/example.el