http://www.perlmonks.org?node_id=971630


in reply to Rosetta PGA-TRAM

A nearly verbatim translation to Ruby:
$rtoa = { :M=>1000, :D=>500, :C=>100, :L=>50, :X=>10, :V=>5, :I=>1 } def roman_to_dec(roman) roman.split(//).map { |c| $rtoa[c.upcase.to_sym] }.reduce { |t, n | +t+n-t%n*2 } end %w[ XLII LXIX mi ].each { |r| puts roman_to_dec r }