Sha256: d20b63e10708b67f921a3420c00d47705048ed54fcd28b77e1f25fcdd455d472

Contents?: true

Size: 1.08 KB

Versions: 22

Compression:

Stored size: 1.08 KB

Contents

Roman_array = [
               [ 1000000, '_M'  ],
               [  900000, '_C_M' ],
               [  500000, '_D'  ],
               [  400000, '_C_D' ],
               [  100000, '_C'  ],
               [   90000, '_X_C' ],
               [   50000, '_L'  ],
               [   40000, '_X_L' ],
               [   10000, '_X'  ],
               [    9000, '_I_X' ],
               [    5000, '_V'  ],
               [    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(val)
  if val < 0 or val >= 5000000
    raise "out of range '#{val}'"
  else
    s = ""
    Roman_array.each { |pair|
      while val >= pair[0]
        s << pair[1]
        val -= pair[0]
      end
    }
    return s
  end
end 

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
partitioned-2.1.0 examples/lib/roman.rb
partitioned-2.0.0 examples/lib/roman.rb
partitioned-1.3.5 examples/lib/roman.rb
partitioned-1.3.4 examples/lib/roman.rb
partitioned-1.3.3 examples/lib/roman.rb
partitioned-1.3.2 examples/lib/roman.rb
partitioned-1.3.1 examples/lib/roman.rb
partitioned-1.3.0 examples/lib/roman.rb
partitioned-1.2.1 examples/lib/roman.rb
partitioned-1.2.0 examples/lib/roman.rb
partitioned-1.1.11 examples/lib/roman.rb
partitioned-1.1.10 examples/lib/roman.rb
partitioned-1.1.9 examples/lib/roman.rb
partitioned-1.1.8 examples/lib/roman.rb
partitioned-1.1.7 examples/lib/roman.rb
partitioned-1.1.6 examples/lib/roman.rb
partitioned-1.1.5 examples/lib/roman.rb
partitioned-1.1.3 examples/lib/roman.rb
partitioned-1.1.1 examples/lib/roman.rb
partitioned-1.1.0 examples/lib/roman.rb