Skip to content

Instantly share code, notes, and snippets.

View amuino's full-sized avatar

Abel Muiño amuino

View GitHub Profile
require 'rspec'
class Fixnum
ROMANS = { 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 }
def to_roman
remaining_number = self
ROMANS.inject ("") do | roman_str, current_number |
times,remaining_number = remaining_number.divmod current_number[1]
roman_str + current_number[0].to_s * times