Skip to content

Instantly share code, notes, and snippets.

@yngwie74
Created January 17, 2012 00:45
Show Gist options
  • Save yngwie74/1623854 to your computer and use it in GitHub Desktop.
Save yngwie74/1623854 to your computer and use it in GitHub Desktop.
Mi implementación original de la kata "Roman Numerals".
#!/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'
@lesthack
Copy link

La mejor de todas las soluciones !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment