Created
January 17, 2012 00:45
-
-
Save yngwie74/1623854 to your computer and use it in GitHub Desktop.
Mi implementación original de la kata "Roman Numerals".
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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
""" | |
Implementación de la kata "Roman Numerals" (http://bit.ly/92cEtq). | |
Esta implementación mapea directamente cada dígito arábigo a su | |
representación romana. Mientras que es la versión más pequeña y | |
clara que he hecho, de alguna forma "feels like cheating". | |
""" | |
_SIMBOLS = ( | |
('', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'), | |
('', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC'), | |
('', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM'), | |
('', 'M', 'MM', 'MMM'), | |
) | |
def romanOf(number): | |
result = [] | |
for numerals in _SIMBOLS: | |
number, remainder = divmod(number, 10) | |
result.append(numerals[remainder]) | |
return ''.join(result[::-1]) | |
if __name__ == '__main__': | |
print romanOf(1999), '-> MCMXCIX' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
La mejor de todas las soluciones !