use strict; use warnings; use Roman; my $testprog = shift or die "usage: $0 program-file\n"; my $datafile = 'tt.txt'; my $cmd = "perl $testprog <$datafile"; sub build_file { my $contents = shift; open(my $fh, '>', $datafile) or die "open '$datafile': $!"; print $fh "$contents\n"; close($fh); } print "Testing $testprog, size=", -s $testprog, " bytes.\n"; for my $i (1..3999) { my $r = uc(roman($i)); print "i=$i r=$r\n"; build_file($r); my $got = `$cmd`; chomp($got); $got eq $i or die "expected '$i' got '$got'\n"; } print "successful\n"; #### s!.!y$IVCXL426(-:$XLMCDIVX$dfor$$_.=5x$&*8%29628;${"$$_ "}=-$_!egfor-4e3..0;print${<>} #### sub arabic { my($arg) = shift; isroman $arg or return undef; my($last_digit) = 1000; my($arabic); foreach (split(//, uc $arg)) { my($digit) = $roman2arabic{$_}; $arabic -= 2 * $last_digit if $last_digit < $digit; $arabic += ($last_digit = $digit); } $arabic; } #### $arabic -= 2 * $last_digit if $last_digit < $digit; #### I1V5X10L50C100D500M1e3=~$_,$\-=2*$}x($}<$')-($}=$')for<>=~/./g;print #### #!perl -lp s#\d#!($\+=$.*$&*(2cmp$'))#eg,$..=0while y/MDCLXVI/CLXVI51/ #### #!perl -n ++$I;$$_=$.*=$^F^=7for V,X,L,C,D,M; print"I=$I V=$V X=$X L=$L C=$C D=$D M=$M\n"; #### I=1 V=5 X=10 L=50 C=100 D=500 M=1000 #### #!perl -p ++$I;$$_=$.*=$^F^=7for VXLCDM=~/(.)/g; s!!($$1<${_&$'}?'-':'+').$$1!eg;$_=eval #### $b=++$I;$$_=$b*=$^F^=7for V,X,L,C,D,M; $\+=$n-$\%$n*2while$n=${+getc};print #### use List::Util 'reduce'; print reduce{$a+$b*($b+1<=>$a)}map{/./;$|--&&(M999D499C99L49X9V4I=~$&+$')*y///c}reverse<>=~/((.)\2*)/g #### I1V5X10L50C100D500M1e3=~$_,$\-=2*$}x($}<$')-($}=$')for<>=~/./g;print #### $\+=$'-2*$'*(-$'>I1V5X10L50C100D500M1e3=~$_-$')for<>=~/./g;print #### 1st 60 robin Perl 2nd 61 arpad Perl 3rd 63 bearstearns Perl 4th 64 kounoike Perl 5th 64 eyepopslikeamosquito Perl 6th 73 flagitious Ruby 7th 73 yvl Ruby 8th 73 bitsweat Ruby 9th 73 jojo Perl 10th 75 shinh Perl #### $/=\1;$\+=-$'*(-$'<=>I1V5X10L50C100D500M1e3=~$_-$')for<>;print #### $\+=$'-2*$'%(I1V5X10L50C100D500M1e3=~$_*$')for<>=~/./g;print #### I1V5X10L50C100D500M1e3 #### M999D499C99L49X9V4I #### $\+=$z-2*$z%($z=M999D499C99L49X9V4I=~$_+$')for<>=~/./g;print #### $\+=$z-2*$z%($z=1 .E.(3^77%ord)%7>>y/VLD//)for<>=~/./g;print $\+=$z-2*$z%($z=.5**y/VLD//.E.(3^77%ord)%7)for<>=~/./g;print $\+=$z-2*$z%($z=5**y/VLD//.E.(42^88*ord)%5)for<>=~/./g;print $\+=$z-2*$z%($z=5**y/VLD//.E.71248%ord()%5)for<>=~/./g;print $\+=$z-2*$z%($z=5**y/VLD//.E.(3&57532/ord))for<>=~/./g;print $\+=$z-2*$z%($z=.1.E.(3^85%ord)%7>>y/VLD//)for<>=~/./g;print #### $\+=$z-2*$z%($z=VLD=~$_*5+IXCM=~$_."E@-")for<>=~/./g;print