Skip to content

Instantly share code, notes, and snippets.

@proudlygeek
Created June 26, 2012 22:43
Show Gist options
  • Save proudlygeek/2999829 to your computer and use it in GitHub Desktop.
Save proudlygeek/2999829 to your computer and use it in GitHub Desktop.
Roman Numbers
def romanize(n)
number_map = [
["M", 1000],
["CM", 900],
["D", 500],
["CD", 400],
["C", 100],
["XC", 90],
["L", 50],
["XL", 40],
["X", 10],
["IX", 9],
["V", 5],
["IV", 4],
["I", 1]
]
number = number_map.map do |symbol, value|
# Rebind higher-scope variable
k,n = n / value, n % value
symbol * k
end.join
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment