No mas!
#!perl -pl y/ //d;s/(? |
Gotcha, Andrew! (Maybe.)
#!perl -pl s/\s//g;s/(? |
Aha! One more rung! This may be my last gasp, though.
#!perl -pl
s/\s//g;$z=qr/\(([^()]+|(??{$z}))*\)|-?\d+/;s#(?<=\S)([*/])($z)# $2 $1#g,s#((?<=[\d)*/])[+-])($z( $z [*/])*)# $2 $1#gwhile$q++<1e4;y/()//d
|
Kill some apparently unneeded groups.
#!perl -pl
s/\s//g;$z=qr/\(([^()]+|(??{$z}))*\)|-?\d+/;s#(?<=\S)([*/])($z)# $2 $1#g,s#((?<=[\d)*/])[+-])($z( $z [*/])*)# $2 $1#gwhile$q++<1e4;s/[()]//g
|
That's more like it! Now as long as noone else moves up at all, I can call it a respectable finish. Hm. Maybe I could hack sf.net...
#!perl -pl
s/\s//g;$z=qr/\(((?>[^()]+)|(??{$z}))*\)|-?\d+/;s#(?<=\S)([*/])($z)# $2 $1#g,s#((?<=[\d)*/])[+-])($z( $z [*/])*)# $2 $1#gwhile$q++<1e4;s/[()]//g
|
#!perl -pl
s/\s//g;
$z=qr/\((?:(?>[^()]+)|(??{$z}))*\)|-?\d+/;
s#(?<=\S)([*/])($z)# $2 $1#g,
s#((?<=[\d)*/])[+-])($z( $z [*/])*)# $2 $1#gwhile$q++<1e4;
s/[()]//g;
|
Squeeze out lots o' whitespace. Sadly, I'm still very very far from the top. But it's a good enough score to at least enter the contest.
never finish test1
#!perl -pl
@a=qw(+- */);sub e{my($l,$o)=@_;if($l-2){do{e($l+1);$o&&push@c,$o}while$o=s#^[$a[$l]]##&&$&}else{s/^\(//?e()+s/^\)//:s/-?\d+//+push@c,$&}}s/\s//g;e;s/$/@c/
|
That was a whole lot of work to go through for a measly two spots in the rankings...
For some reason this scores 174.29 when i test it. Hopefully PGAS isn't missing something.
#!perl -pl
s/\s//g;
$p=qr/\((?:(?>[^()]+)|(??{$p}))*\)/;
$z=qr/$p|-?\d+/;
s#(?<=\S)([*/])($z)# $2 $1#g,
s#((?<=[\d)*/])[+-])($z( $z [*/])*)# $2 $1#gwhile($q++<1e4);
s/[()]//g;
|
A last (pathetic) gasp?
#!perl -pl
@a=qw(+- */);s/\s//g;do{push@c,$o[$l]||();($l%3>1&&(s/^\)//||s/^-?\d+/$f=push@c,$&;""/e))||($l%3>1&&s/^\(//||!$f||($o[$l]=s#^[$a[$l%3]]##&&$&))&&($l+=2,$f=0)}while$l--;s/$/@c/
|
Still don't know why my 159 solution failed...
#!perl -pl
@a=qw(+- */);s/\s//g;do{push@c,$o[$l]||();if($l%3>1&&s/^((\))|-?\d+)//){$f=push@c,$1if!$2}elsif($l%3>1&& s/^\(//||!$f||($o[$l]=s#^[$a[$l%3]]##&&$&)){$l+=2;$f=0}}while$l--;s/$/@c/
|
New algorithm. Hopefully this one will work on your computers too!
#!perl -pl
@a=qw(+- */);
s/\s//g;
do{push@c,$o[$l]||();if($l%3==2&&s/^(\)|(-?\d+))//){$l--;if(defined$2){push@c,$2;$found=1}}elsif($l%3==2&&s/^\(//||!$found||($o[$l]=s#^[$a[$l%3]]##&&$&)){$l++;$found=0}else{$l--}}until$l==-1;s/$/@c/
|
Get rid of long variable names. Realized that arith/mult. expressions are perfect for do while loops.
doesnt finish fist test.
#!perl -pl
@a=qw(+- */);
sub e{
my ($l,$o) = @_;
if ($l-2) {
do {
e($l+1);
$o && push @c,$o
} while $o = s#^[$a[$l]]## && $&
} else {
s/^\(// ? e() + s/^\)// : s/-?\d+// + push @c, $&
}
}
s/\s//g;
e;s/$/@c/
|
Minimal squeezing, but arithmetic & multiplicative expressions are almost the same, so shoehorn all three types into one subroutine that's called with a "level".
#!perl -pl
@a=qw(+- */);
sub e2r {
my $level = pop;
if ($level == 2) {
s/^\(// && &e2r x s/^\)// || s/-?\d+// && $&
} else {
my $exp = &e2r($level+1);
while (s#^[$a[$level]]##) {
my $op = $&;
$e2 = &e2r($level+1);
$exp .= " $e2 $op";
}
$exp;
}
}
s/\s+//g;
$_=e2r
|
I'm entering this contest against my better judgement. My eyeballs still ache from mushing them back in on August 8...
#!perl -nl
use strict;
s/\s+//g; # first get rid of whitespace
my $a = a2r();
print $a;
# arithmetic expression is mult. exp. followed by N pairs of
# arithmetic operator and mult. exp.
sub a2r {
my $mult = m2r();
while (s/^[+-]//) {
my $op = $&;
my $m2 = m2r();
$mult .= " $m2 $op";
}
$mult;
}
# multiplicative expression is unary exp. followed by N pairs of
# mult. operator and unary exp.
sub m2r {
my $unary = u2r();
while (s#^[*/]##) {
my $op = $&;
my $u2 = u2r();
$unary .= " $u2 $op";
}
$unary;
}
# Unary expression is integer or parenthesized arith. exp.
sub u2r {
if (s/^\(//) {
my $a = a2r();
s/^\)//;
$a;
} else {
s/-?\d*//;
$&;
}
}
|