Skip to content

Instantly share code, notes, and snippets.

@vijithmv499
Created April 24, 2016 13:19
Show Gist options
  • Select an option

  • Save vijithmv499/78feac9602a1bdbe71a823d7cb7aed41 to your computer and use it in GitHub Desktop.

Select an option

Save vijithmv499/78feac9602a1bdbe71a823d7cb7aed41 to your computer and use it in GitHub Desktop.
Exercism assignment 8 - Number to Roman nemerals conversion (http://exercism.io/exercises/ruby/roman-numerals/readme)
class Fixnum
VERSION = 1
NUMERALS = {
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 to_roman
compute(self)
end
def compute(num,res = '')
NUMERALS.keys.each do |x|
quo,mod = num.divmod(x)
res << NUMERALS[x] * quo
num = mod
end
return res
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment