Created
April 29, 2016 13:44
-
-
Save vandersonmota/fbb4735a003b2fc676f9796c5eaf4ff1 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
""" | |
Fui num dia do Grupo de Erlang, acabamos fazendo um dojo. | |
Créditos da solução - Seu Carlos Flores =) | |
""" | |
# versão 1 | |
arabicos = [1000, 900,500,400,100,90,50,40,10,9,5,4,1] | |
romanos = ['M','CM','D','CD','C','XC','L','XL','X','IX','V','IV', 'I'] | |
def converter(num): | |
convertido = '' | |
indice = 0 | |
while num > 0: | |
qtd = num/arabicos[indice] | |
convertido += qtd*romanos[indice] | |
num -= qtd * arabicos[indice] | |
indice += 1 | |
return convertido | |
# versão 2 | |
arabicos = [1000, 900,500,400,100,90,50,40,10,9,5,4,1] | |
romanos = ['M','CM','D','CD','C','XC','L','XL','X','IX','V','IV', 'I'] | |
def converter(num): | |
convertido = '' | |
for indice in range(0, len(arabicos)): | |
qtd = num/arabicos[indice] | |
convertido += qtd*romanos[indice] | |
num -= qtd * arabicos[indice] | |
return convertido | |
#versão 3 | |
arabicos = [1000, 900,500,400,100,90,50,40,10,9,5,4,1] | |
romanos = ['M','CM','D','CD','C','XC','L','XL','X','IX','V','IV', 'I'] | |
def converter(num): | |
convertido = '' | |
for indice, arabico in enumerate(arabicos): | |
qtd = num/arabico | |
convertido += qtd*romanos[indice] | |
num -= qtd * arabico | |
return convertido | |
#versão final | |
arabicos = [1000, 900,500,400,100,90,50,40,10,9,5,4,1] | |
romanos = ['M','CM','D','CD','C','XC','L','XL','X','IX','V','IV', 'I'] | |
def converter(num): | |
convertido = '' | |
for indice, arabico in enumerate(arabicos): | |
convertido += (num/arabico)*romanos[indice] | |
num %= arabico | |
return convertido |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment