Skip to content

Instantly share code, notes, and snippets.

@AlexAvlonitis
Created October 11, 2021 12:49
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 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