Created
December 12, 2016 15:29
-
-
Save JDeuce/7355747f71b23188deddd0a27a8c6b28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_rdecode = dict(zip('MDCLXVI', (1000, 500, 100, 50, 10, 5, 1))) | |
def decode( roman ): | |
result = 0 | |
for r, r1 in zip(roman, roman[1:]): | |
rd, rd1 = _rdecode[r], _rdecode[r1] | |
result += -rd if rd < rd1 else rd | |
return result + _rdecode[roman[-1]] | |
if __name__ == '__main__': | |
for r in 'MCMXC MMVIII MDCLXVI'.split(): | |
print( r, decode(r) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment