II plus III minus I ##```## IV ##``````## #!perl -lp map{\$_.=(!y/IVXLC/XLCDM/,I,II,III,IV,V,VI,VII,VIII,IX)[\$&]while s/\d//;\$\$_=\$n++}@R=0..3999; y/mp/-+/;s/\w+/\${\$&}/g;\$_=\$R[eval] ##``````## #!perl -lp # r() converts an arabic number (1..3999 or -3999..-1) to a roman numeral # using a non-destructive variation of Ton's magic formula (HART). sub r{my\$s;(\$s.=5x\$_*8%29628)=~y\$IVCXL426(-:\$XLMCDIVX\$dfor/./g;\$s} y/iul-z/-\$+/d; # Step 1: convert plus and minus to +\$ and -\$ s''\$'; # Step 1: prepend \$ \$\$_=r(),\$\$\$_=\$_ for-3999..-1; # Step 2: build two sets of symbolic references \$_=\${+eval}; # Step 3: eval the expression ##``````## #!perl -lp040 \$s=/m/ if/u/;(\$y=I1V5X10L50C100D500M1000IV4IX9XL40XC90CD400CM900)=~/\$&/,\$i=\$t+=\$s^"\$;">(\$;=\$')?-\$;:\$;while s/.\$//}{1while\$y=~/(\D+)\$i/&&\$t>=\$i?(\$_.=\$1,\$t-=\$i):\$i-- ##``````## #!perl -lp @@{@@=map{\$_,\$_.0,\$_*100}4,5,9,10}=qw(IV XL CD V L D IX XC CM X C M);for\$~(@@){s/\$@{\$~}/"I "x\$~/ge}s/I//while s/m\w* +I/m /;\$~=y/I//cd;s/I{\$~}/\$@{\$~}||\$&/gewhile\$~-- ##``````## { in => "MD plus I\n", out => 'MDI' . "\n" }, { in => "MD minus I\n", out => 'MCDXCIX' . "\n" }, ##``````## #!perl -lp \$==\$_,s!.!y\$IVCXL91-I0\$XLMCDXVIII\$dfor\$_[\$=].=4x\$&%1859^7;5!egfor+0..3999;@&{@_}=0..@_;y/il-z/-+/d;s/\w+/\$&{\$&}/g;\$_=\$_[eval] ##``````## #!perl -lp s!.!y\$IVCXL91-I0\$XLMCDXVIII\$dfor\$X[\$_].=4x\$&%1859^7!egfor+0..3999;@Y{@X}=0..@X;y/m/-/;s/\w+/+\$Y{\$&}/g;\$_=\$X[eval] ##``````## #!perl -lp map{y/IVXLC/XLCDM/,s!\d!\$&^4?\$&^9?V x(\$&>3).I x(\$&%5):IX:IV!ewhile//;\$\$_=\$n++}@d=0..3999;y/m/-/;s/\w+/+\${\$&}/g;\$_=\$d[eval] ##``````## #!perl -lp sub'_{\$;=0;(\$;.=5x\$_*8%29628)=~y\$IVCXL426.-X\$XLMCDIVX\$dfor/./g;\$;}y;mp;-+;;s>\w+>(grep\$&eq&_,1..1e4)[0]>eg;\$_=_\$_=eval ##``````## #!perl -lp @%=map{my\$a;s/./y!IVCXL91-80!XLMCDXVIII!dfor\$a.=4x\$&%1859^7/eg;\$\$a=\$/--;\$a}0..3999;y/i/-/;s/\w+/\${\$&}/g;\$_=\$%[-eval] ##``````## #!perl -pl y/i-z/-+/s;for\$a(1..4e3){\$a=~s#.#(\$n[\$a].=4x\$&%1859^7)=~y\$IVCXL91-I0\$XLMCDXVIII\$d;s/\b\$n[\$a]\b/\$a/g#ge}\$_=\$n[eval] ##``````## #!perl -pl @;=map{\$a=0;(\$a.=4x\$_%1859^7)=~y!IVCXL91-80!XLMCDXVIII!dfor/./g;\$\$a=\$_;\$a}s''\$'>y/isl-{/-\$+ /..3999;\$_=\$;[eval] ##``````## #!perl -pl s|.|y;CLXVI624.-=;MDCLXXVI;dfor\$\$_.=5x\$&*8%29628;\$&|ge,\$\$\$_=\$_^Kfor-4e3..o;s;\w+;\${\$&}|\$&&'-';ge;\$_=\${+eval} ##``````## #!perl -lp y,iul-~,-\$+,d,\$_=eval,\${\$@}=1..!s/./y@IVCXL91-:0@XLMCDXVIII@dfor\$@.=4x\$&%1859^7/egfor\$...3999,u.\$_;\$_=\$@ ##``````## #!perl -pl \$_=\${s!.!y\$XLIVC246,-:\$CDXLMVIX\$dfor\$\$_.=8x\$&*5%29628;\$\$\$_=\$_!gefor-4e3..s''\$'/y/isl-~/-\$+/d;eval} ##``````## #!perl -pl s!.!y\$IVCXL426(-:\$XLMCDIVX\$dfor\$\$_.=5x\$&*8%29628;\$\$\$_=\$_!egfor-4e3..y/iul-}/-\$+ /%s''\$';*_=eval ```