Aquí les dejo, mi código para hacer un Decimal a Romanos
#Roman Numerals
Roman_Table = {
1000 => "M",
900 => "CM",
500 => "D",
400 => "CD",
100 =>"C",
90 => "XC",
50 => "L",
40 => "XL",
10 => "X",
9 => "IX",
5 => "V",
4 => "IV",
1 => "I"
}
$Result = ""
def Roman_Number(number)
while number > 0
Roman_Table.keys.sort {|a,b| b<=>a}.inject do |key,value|}
if number >= value.to_i
$Result << Roman_Table[value]
number = number - value.to_i
break
end
end
end
end
print "Ingresa un numero: "
$Numero = gets
Roman_Number($Numero.chop!.to_i)
print "#{$Result}\n"
Saludos,
Blag.
No comments:
Post a Comment