public
Created

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
n=[]
n['M'] = 1000
n['CM'] = 900
n['D'] = 500
n['CD'] = 400
n['C'] = 100
n['XC'] = 90
n['L'] = 50
n['XL'] = 40
n['X'] = 10
n['IX'] = 9
n['V'] = 5
n['IV'] = 4
n['I'] = 1
addroman =( first, second) ->
first1 = analyse(first)
second2 = analyse(second)
result = first1 + second2
result
 
romanThis = (value) ->
out = ""
for index, val of n
while value >= val
debugger;
value -= val
out+= index
debugger;
out
 
analyse = (number) ->
out = 0
previous = 0
for i in [0...number.length]
o = number.length - i
numb = n[number.charAt(o-1)];
if(previous<numb)
out = out + numb
previousStreak = false
else if(previous==numb)
if previousStreak is true
out = out - numb
else
out = out + numb
else
previousStreak = true
out = out - numb
previous = numb
out
 
 
console.log romanThis( addroman("CCCLXIX", "CDXLVIII") )
console.log romanThis(9)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.