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.180 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.179 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.178 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.177 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.176 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.175 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.174 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.173 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.172 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.171 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.170 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.169 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.167 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.166 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.165 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.164 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.163 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.162 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.161 tracks/elisp/exercises/roman-numerals/example.el
trackler-2.2.1.160 tracks/elisp/exercises/roman-numerals/example.el