Roman to Arabic numbers conversion

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

Roman to Arabic numbers conversion

Post by Mr. Kibernetik » Sun Aug 06, 2017 5:52 am

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