Code Golf: Roman to Decimal
Feb 07, 2007
Here is my submission for the Roman to Deciman challenge. Code size: 121 bytes.
v={'I',1,'V',5,'X',10,'L',50,'C',?d,'D',500,'M',1000}
y=q=0
gets.chop.split('').each{|n|j=v[n]
y+=j-(q<j ?q*2:0)
q=j}
p y
Feb 07, 2007
Here is my submission for the Roman to Deciman challenge. Code size: 121 bytes.
v={'I',1,'V',5,'X',10,'L',50,'C',?d,'D',500,'M',1000}
y=q=0
gets.chop.split('').each{|n|j=v[n]
y+=j-(q<j ?q*2:0)
q=j}
p y