Skip to content

Instantly share code, notes, and snippets.

@ELI7VH
Created March 11, 2018 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ELI7VH/4fe4e0673700c2fa293301baf9e90b32 to your computer and use it in GitHub Desktop.
Save ELI7VH/4fe4e0673700c2fa293301baf9e90b32 to your computer and use it in GitHub Desktop.
roman_mapping = {
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"
}
def map_dat_roman(roman_mapping, number, result)
if (number > 0)
roman_mapping.each do |k,v|
if (number / k) >= 1
result += v
new_number = number - k
p new_number, result
sleep 1
map_dat_roman(roman_mapping, new_number, result)
end
end
else
p 'result reached'
end
return result
end
number = 2541
result = ''
p map_dat_roman(roman_mapping, number, result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment