Arc Forumnew | comments | leaders | submitlogin
3 points by chaos 6171 days ago | link | parent

Because I'm reddit-damaged:

    (def unfold (f x)
      (let res (f x)
        (if res
            (cons (car res) (unfold f (cdr res)))
            ())))

    (def romanize (i)
      (let r '((M 1000)(CM 900)(D 500)(CD 400)(C 100)(L 50)(XL 40)(X 10)(IX 9)(V 5)(IV 4)(I 1))
        (unfold 
         (fn ((i . ((r n) . rst)))
             (if (is i 0)
                   ()
                 (>= i n)
                   (cons r (cons (- i n) `((,r ,n) . ,rst)))
                   (cons "" (cons i rst))))
         (cons i r))))
    (apply string (romanize 999))