- or download this
use strict;
use warnings;
...
for my $r (@testdata) {
print "$r: ", roman_to_dec($r), "\n";
}
- or download this
# Note: use v5.12+ implies use strict (and enables feature state)
# use v5.36+ implies use strict and warnings (and enables featur
+e state)
...
for my $r (@testdata) {
print "$r: ", roman_to_dec($r), "\n";
}
- or download this
XLII: 42
LXIX: 69
mi: 1001
- or download this
sub roman_to_dec {
my $t = 0;
...
}
return $t;
}
- or download this
def roman_to_dec(r, __rtoa = dict(M=1000, D=500, C=100, L=50, X=10, V=
+5, I=1) ):
return reduce( lambda t,n: t+n-t%n*2, (__rtoa[c] for c in r.upper())
+ )
...
testdata = [ "XLII", "LXIX", "mi" ]
for r in testdata:
print r, ":", roman_to_dec(r)
- or download this
from functools import reduce
def roman_to_dec(r, __rtoa = dict(M=1000, D=500, C=100, L=50, X=10, V=
+5, I=1) ):
...
testdata = [ "XLII", "LXIX", "mi" ]
for r in testdata:
print( r, ":", roman_to_dec(r) )
- or download this
{-# OPTIONS_GHC -fglasgow-exts -Wall #-}
...
main :: IO ()
main = do
putStrLn $ (concat $ intersperse "\n" (map (\c -> (myshow roman_to_d
+ec c)) testdata))
- or download this
#include <cctype>
#include <iostream>
...
}
return 0;
}
- or download this
// Note: there are less than 256 initializers in this table;
// the uninitialized ones are guaranteed by ANSI C to be
...
{
return t+urtoa(c)-t%urtoa(c)*2;
}