Roman to Arabic numbers conversion

Post Reply
User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Roman to Arabic numbers conversion

Post by Mr. Kibernetik »

Code: Select all

r = #.input("Input Roman number:")

n = [1,5,10,50,100,500,1000]
a,m = 0
> i, #.size(r)..1, -1
  v,c = n[#.pos("IVXLCDM",#.mid(#.upper(r),i))]
  ? v<m, v = -v
  ? c>m, m = c
  a += v
<

#.output("Arabic number: ",a)

Post Reply