Hospelian Arabic to Roman Transform (HART) shortened

Andrew Savige <[email protected]> Mon, 24 Dec 2012 23:04:21 -0800 (PST)
Newsgroups gmane.comp.lang.perl.golf
Message-ID <[email protected]>
Continuing the thread from Jan 2007 after more than five years,=0Athe famou=
s "Hospelian Arabic to Roman Transform" aka HART, as=0Aplayed by Ton in the=
 Fonality Christmas golf challenge, has been=0Ashortened by one stroke by p=
rimo. Test program showing Ton's two=0Aoriginal HART magic formulae and pri=
mo's improvement follows:=0A=0Ause strict;=0Ause Roman;=0A=0Asub ton1 { my =
$t =3D shift; my $s;=0A($s.=3D4x$_%1859^7)=3D~y/IVCXL91-80/XLMCDXVIII/d=0Af=
or $t=3D~/./g; return $s }=0A=0Asub ton2 { my $t =3D shift; my $s;=0A($s.=
=3D5x$_*8%29628)=3D~y/IVCXL426(-:/XLMCDIVX/d=0Afor $t=3D~/./g; return $s }=
=0A=0Asub pmo1 { my $t =3D shift; my $s;=0A($s.=3D"32e$_"%72726)=3D~y/CLXVI=
60-9/MDCLXVIX/d=0Afor $t=3D~/./g; return $s }=0A=0Asub pmo2 { my $t =3D shi=
ft; my $s;=0A($s.=3D"57e$_"%474976)=3D~y/CLXVI0-9/MDCLXIXV/d=0Afor $t=3D~/.=
/g; return $s }=0A=0Afor my $i (1..3999) {=0A=A0 =A0 my $r =A0=3D uc roman(=
$i);=0A=A0 =A0 my $t1 =3D ton1($i);=0A=A0 =A0 my $t2 =3D ton2($i);=0A=A0 =
=A0 my $p1 =3D pmo1($i);=0A=A0 =A0 my $p2 =3D pmo2($i);=0A=A0 =A0 print "$i=
: $r\n";=0A=A0 =A0 $r eq $t1 or die "t1: expected '$r' got '$t1'\n";=0A=A0 =
=A0 $r eq $t2 or die "t2: expected '$r' got '$t2'\n";=0A=A0 =A0 $r eq $p1 o=
r die "p1: expected '$r' got '$p1'\n";=0A=A0 =A0 $r eq $p2 or die "p2: expe=
cted '$r' got '$p2'\n";=0A}=0Aprint "all tests successful\n";=0A=0AFor more=
 details: http://perlmonks.org/?node_id=3D1009126=0A=0A/-\=0A