in reply to Rosetta PGA-TRAM
Here's the code, which works with today's Rakudo:
sub roman-to-dec($x) { state %rtoa = M=>1000, D=>500, C=>100, L=>50, X=>10, V=>5, I=>1; $x.uc.split('').map({ %rtoa{$_} }).reduce: { $^a+$^b-$a%$b*2 } } my @testdata = <XLII LXIX mi>; for @testdata -> $r { say "$r: ", roman-to-dec($r); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Rosetta PGA-TRAM
by John M. Dlugosz (Monsignor) on Jun 17, 2009 at 22:33 UTC | |
by moritz (Cardinal) on Jun 17, 2009 at 22:42 UTC | |
by John M. Dlugosz (Monsignor) on Jun 17, 2009 at 22:56 UTC | |
Re^2: Rosetta PGA-TRAM
by John M. Dlugosz (Monsignor) on Jun 17, 2009 at 22:53 UTC |