Skip to content

Commit

Permalink
roman_numbers startswith uses beg
Browse files Browse the repository at this point in the history
  • Loading branch information
xtof-durr committed Mar 29, 2016
1 parent 7b8bf41 commit a30c9d1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tryalgo/roman_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ def roman2int(s):
"""
val = 0
pos10 = 1000
beg = 0
for pos in range(3, -1, -1):
for digit in range(9,-1,-1):
r = roman[pos][digit]
if s.startswith(r):
s = s[len(r):]
if s.startswith(r, beg):
beg += len(r)
val += digit * pos10
break
pos10 //= 10
Expand Down

0 comments on commit a30c9d1

Please sign in to comment.