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.38 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.37 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.36 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.35 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.34 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.33 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.32 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.31 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.30 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.29 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.28 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.27 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.26 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.25 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.24 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.23 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.22 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.21 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb
trackler-2.2.1.20 tracks/ruby/exercises/roman-numerals/.meta/solutions/roman_numerals.rb