Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
Total Post History
7-Day Post History
- New Posts:
- New Topics:
- Active Topics:
Our newest member
All times are UTC [ DST ]
Always post answers in a "Hidecode" tag, so that others have a chance to answer the question too.
Valid characters are I, V, X, L, C, D, and M
I can be subtracted from V and X only.
X can be subtracted from L and C only.
C can be subtracted from D and M only.
V, L, and D can never be subtracted.
In other words 99 = LXXXXVIIII not IC but since we have repeated numbers here(LXXXXVIIII ) we don't want this one
Here is a sample
can you write a program that list all of them till 1000?
Personal and/or non database related blog
- LTD Admin
- Posts: 21784
- Joined: Wed Oct 10, 2007 6:43 pm
- Location: Princeton, New Jersey, USA,World, Solar System, Milky Way, Universe and Beyond
- (def -:- (juxt quot rem))
- (defn digits
- "Digits in a positive integer. Defaults to a base of 10."
- ([n] (digits 10 n))
- ([b n]
- (loop [n n, ds nil]
- (let [[q r] (-:- n b), ds (cons r ds)]
- (if (zero? q)
- (recur q ds))))))
- (def roman-chars
- (partition 3 2 (list* nil nil "MDCLXVI")))
- (defn xlat-digit
- "Translate a digit."
- [digit [ten five one]]
- (let [[q r] (-:- digit 5), zq (zero? q)]
- (if (= 4 r)
- [one (if (zero? q) five ten)]
- (concat (if-not zq [five]) (repeat r one)))))
- (defn pad-front
- (let [n (- 4 (count ds))]
- (if (pos? n)
- (concat (repeat n 0) ds)
- (defn int->roman [n]
- (apply str
- (mapcat xlat-digit
- (pad-front (digits n))
- (defn no-repeats?
- (every? #(apply not= %) (partition 2 1 xs)))
- (defn non-repeating-romans
- "Return the non-repeating roman numerals up to n (default 1000)."
- ( (non-repeating-romans 1000))
- (filter no-repeats?
- (map int->roman
- (range 1 (inc n))))))
- ;; Print a list like the one in the example
- (doseq [x (non-repeating-romans)]
- (prn x))
- Posts: 1
- Joined: Thu Jan 12, 2012 10:25 pm