[ create a new paste ] login | about

Link: http://codepad.org/cHeKqAuF    [ raw code | output | fork ]

mohit_at_codepad - Haskell, pasted on Mar 13:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
-- Written by Mohit Jain
-- Problem statement: Print list of roman numerals from 1 to 50

main = solveForList [1..50]

solveForList = putStrLn . unlines . map toRomanString
toRomanString n = toRomanTens t ++ toRomanUnits u where
                  t = n `div` 10
                  u = n `mod` 10
                  toRomanTens  x = romanTensList  !! x
                  toRomanUnits x = romanUnitsList !! x
                  romanUnitsList = ["", "I", "II", "III", "IV",
                                    "V", "VI", "VII", "VIII", "IX"]
                  romanTensList  = ["", "X", "XX", "XXX", "XL", "L"]


Output:
I
II
III
IV
V
VI
VII
VIII
IX
X
XI
XII
XIII
XIV
XV
XVI
XVII
XVIII
XIX
XX
XXI
XXII
XXIII
XXIV
XXV
XXVI
XXVII
XXVIII
XXIX
XXX
XXXI
XXXII
XXXIII
XXXIV
XXXV
XXXVI
XXXVII
XXXVIII
XXXIX
XL
XLI
XLII
XLIII
XLIV
XLV
XLVI
XLVII
XLVIII
XLIX
L



Create a new paste based on this one


Comments: