Factorial
Score: 44.11 (pass)
Ah, the other regexp could be changed to ?? too.
#!perl -l
$_*=$`%9e9,??for~4=~?0*$?..pop;print$`%10
|
Score: 44.12 (pass)
Improve tiebreaker marginally. (Dammit, where's the missing 0.0013?).
#!perl -l
$_*=$`%9e9,//for~4=~/0*$/..pop;print$`%10
|
Score: 44.12 (pass)
Finally got the tiebreaker. I hope...
#!perl -l
$_*=$`%9e9,//for~4=~?0*$?..pop;print$`%10
|
Score: 44.13 (pass)
Hmm... It seems that the map was a pessimization. Back to for.
#!perl -l
$_*=$`%9e9,//for+1=~/0*$/..pop;print$`%10
|
Score: 45.11 (pass)
Use *=
#!perl -l
map{$_*=$`%9e9;//}1=~/0*$/..pop;print$`%10
|
Score: 46.10 (pass)
#!perl -l
map{//for$_*$`%9e9}1=~/0*$/..pop;print$`%10
|
Score: 46.13 (pass)
Use the return value of the initial regexp as part of the loop condition. Saves an amazing 2 strokes.
#!perl -l
($`%9e9*$_)=~//for+1=~/0*$/..pop;print$`%10
|
Score: 48.13 (pass)
Wohoo!! Empty regexps to the rescue.
#!perl -l
1=~/0*$/;($`%9e9*$_)=~//for 1..pop;print$`%10
|
Score: 49.10 (pass)
Initialize $} with ++ in the loop generator, instead of using ||1 in the loop body.
#!perl -l
($}=$}%1e9*$_)=~s~0*$~~for++$}..pop;print$}%10
|
Score: 50.09 (pass)
Doh! Grab the last number with %10 instead of chop.
#!perl -l
($~=$~%1e9*$_||1)=~s~0*$~~for 0..pop;print$~%10
|
Score: 52.10 (pass)
Replace a regexp with a modulo.
#!perl -l
($p=$p%1e7*$_||1)=~s/0*$//for 0..pop;print+chop$p
|
Score: 55.11 (pass)
This is pretty slow for the later tests. Getting the solution for 9999! takes about 70 seconds on my 600MHz machine.
#!perl -l
s/.{1,6}$/$&*++$i/e,s/0*$//for($_=1)x+pop;print+chop
|