Skip to content

Instantly share code, notes, and snippets.

@AlexAvlonitis
Created October 11, 2021 12:49
Show Gist options
  • Save AlexAvlonitis/d174e83c221ab56a54567eae94ba484a to your computer and use it in GitHub Desktop.
Save AlexAvlonitis/d174e83c221ab56a54567eae94ba484a to your computer and use it in GitHub Desktop.
Roman numerals converter
# solution from https://www.codewars.com/kata/reviews/51b62bf7a9c58071c6000026/groups/560d5575e3ff138f6400001d
NUMS = [
[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 solution num
str = ""
NUMS.each do |number, sub|
while num >= number
str << sub
num -= number
end
end
str
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment