Sha256: 41ff5661895819be6795a0c1866b59b87bfb3d4ede664c506ea819258f79963a

Contents?: true

Size: 499 Bytes

Versions: 159

Compression:

Stored size: 499 Bytes

Contents

module BookKeeping
  VERSION = 2
end

class Integer
  def to_roman
    i = self
    s = ''
    roman_mappings.each do |arabic, roman|
      while i >= arabic
        s << roman
        i -= arabic
      end
    end
    s
  end

  def roman_mappings
    {
      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'
    }
  end
end

Version data entries

159 entries across 159 versions & 1 rubygems

Version Path
trackler-2.2.1.78 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.77 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.76 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.75 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.74 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.73 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.72 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.71 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.70 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.69 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.68 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.67 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.66 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.65 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.64 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.63 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.62 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.61 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.60 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.59 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb