Skip to content
This repository was archived by the owner on Dec 30, 2025. It is now read-only.
This repository was archived by the owner on Dec 30, 2025. It is now read-only.

Working solution for Problem #92 is failing on the site #284

@bbakersmith

Description

@bbakersmith

I wrote the following solution, which passes locally in Clojure version 1.7 -- but it fails the first unit test on 4clojure.com

(fn [roman]
    (let [numerals {\M 1000
                    \D 500
                    \C 100
                    \L 50
                    \X 10
                    \V 5
                    \I 1}
          groupings (reduce
                      (fn [res n]
                        (let [[g r] (rest
                                      (re-find
                                        (re-pattern (str "(.*" n ")?(.*)"))
                                        (res :remainder)))]
                          (assoc res n g :remainder r)))
                      {:remainder roman}
                      (keys numerals))]
      (reduce
        (fn [total [k s]]
          (apply +
                 total
                 (map
                   (fn [n] 
                     (let [n-val (numerals n)] 
                       (if (= k n) n-val (* -1 n-val))))
                   (seq s))))
        0
        groupings)))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions