Infix to RPN

Score: 112.63 (pass)

Yet another stroke... today is a good day. Went back to using $" to avoid having to use /s or \C in the inner regex.

#!perl -lp
y/()	 /	_/d+s@	|(?<=\w)\D@($"=" $&$\"")=~s#_(.*?)	|(\S)([ */${":"x/\G[+-]/}]*)#$2 #;$+@eg;$_.=$";y/ //s+chop

Score: 113.28 (pass)

Continuing with the theme of absolute obfuscation... ')' is now replaced by '_' to make the use of \w possible.

#!perl -lp
y/()	 /	_/d+s@	|(?<=\w)\D@($/="
$&$/")=~s#_(\C*?)	|(\S)([
*/${":"x/\G[+-]/}]*)#$2
#;$+@eg;$_.=$/;y/
/ /s+chop

Score: 115.26 (pass)

How absolutely confusing! Replacing parens with whitespace makes this probably the most obfuscated program I've ever written.

#!perl -lp
y/)( 	/ 	/d+s@	|(?<=\d| )\D@($/="
$&$/")=~s# (.*?)	|(\S)([
*/${":"x/\G[+-]/}]*)#$2
#s;$+@eg;$_.=$/;y/
/ /s+chop

Score: 117.64 (pass)

Simple removal of an unnecessary space character. Now I just need to find the other 20 unnecessary characters.

#!perl -lp
y/ 	//d+s@\(|(?<=[\d)])\D@($"=" $&$\"")=~s!\)(.*?)\(|([^ (])([ */${':'x/\G[+-]/}]*)!$2 !;$+@eg;$_.=$";y/ //s+chop

Score: 118.64 (pass)

Who knew you could interpolate $" as "$\""? Strange...

#!perl -lp
y/ 	//d+s@\(|(?<=[\d)])\D@($"=" $& $\"")=~s!\)(.*?)\(|([^ (])([ */${':'x/\G[+-]/}]*)!$2 !;$+@eg;$_.=$";y/ //s+chop

Score: 119.58 (pass)

Just a tiebreak improvement, but hey, every little bit helps.

#!perl -lp
y/ 	//d+s@\(|(?<=[\d)])\D@($*=" $& $*")=~s!\)(.*?)\(|([^ (])([ */${':'x/\G[+-]/}]*)!$2 !;$+@eg;$_.=$*;y/ //s+s/ $//

Score: 119.61 (pass)

Inline, inline, inline.

#!perl -lp
y/ 	//d+s@\(|(?<=[\d)])\D@($s=" $& $s")=~s!\)(.*?)\(|([^ (])([ */${':'x/\G[+-]/}]*)!$2 !;$+@eg;$_.=$s;y/ //s+s/ $//

Score: 121.59 (pass)

Accidentally stumbled across the fact that '+' does not need to be popped off the stack when '+' or '-' is seen. I think this is the first time I've ever used $:, ever.

#!perl -lp
y/ 	//d+s@\(|(?<=[\d)])\D@$z=$:x/\G[+-]/;($s=" $& $s")=~s+\)(.*?)\(|([^( ])([ */$z]*)+$2 +;$+@eg;$_.=$s;y/ //s+s/ $//

Score: 123.59 (pass)

Tiebreaker improvement. Hopefully the tab char comes through okay.

#!perl -lp
y/ 	//d+s@\(|(?<=[\d)])\D@$z="+-"x!/\G[+-]/;($s=" $& $s")=~s/\)(.*?)\(|([^( ])([^($z]*)/$2 /;$+@eg;$_.=$s;y/ //s+s/ $//

Score: 123.64 (pass)

Not my best solution, but using the usage of $: is interesting.

#!perl -lp
y/ 	//d+s@\(|(?<=[\d)])\D@$z=!/\G[+-]/&&'"';($"=" $&$\"")=~s+\)(.*?)\(|([^ (])([*/$:$z]*)+$2 +;$+@eg;$_.=$";y/ //s+chop

Score: 123.65 (pass)

Two more strokes with y///s. Now, how to avoid the need for s/ $// ?

#!perl -lp
s/\s//g;s@\(|(?<=[\d)])\D@$z="+-"x!/\G[+-]/;($s=" $& $s")=~s!\)(.*?)\(|([^( ])([^($z]*)!$2 !;$+@eg;$_.=$s;y/ //s;s/ $//

Score: 125.59 (pass)

Whoa! One of the thousand combinations I tried actually yielded a better score!

#!perl -p
s/\s//g;s@\(|(?<=[\d)])\D@$z="+-"x!/\G[+-]/;($s=" $& $s")=~s/\)(.*?)\(|([^( ])([^($z]*)/$2 /;$+@eg;$_.=$s;$_="@{[split]}
"

Score: 126.59 (pass)

Okay, that \G is freaking me out. I don't know why I even tried it.

#!perl -p
s/\s//g;s@\(|(?<=[\d)])\D@$z=/\G[+-]/||"+-";($s=" $& $s")=~s/\).*?\(|(?<=[^( ])[^($z]*/ /;$&@eg;$_.=$s;$_="@{[/[*-9]+/g]}
"

Score: 127.60 (pass)

Trying to start to use whitespace wisely. Failing quite miserably so far.

#!perl -p
s/\s//g;s@\(|(?<=[\d)])\D@$z="+-"x$&!~/[+-]/;($s=" $&$s ")=~s/\).*?\(|(?<=[^( ])[^($z]*/ /;$&@eg;$_.=$s;$_="@{[/[*-9]+/g]}
"

Score: 128.47 (pass)

Negation of =~ instead of the character class saves another stroke.

hmm .. you sure do keep a ref buzy :)

#!perl -p
s/\s//g;s@\(|(?<=[\d)])\D@$z="+-"x$&!~/[+-]/;($s="$& $s")=~s/\)(.*?)\(|(?<=^[^(])([^($z]*)/ /;$+@eg;s/$/
$s/;$_="@{[split]}
"

Score: 129.47 (pass)

Oops, I had an unnecessary ( in a character class. Now if I could just get rid of $z...

#!perl -p
s/\s//g;s@\(|(?<=[\d)])\D@$z="+-"x$&=~/[^+-]/;($s="$& $s")=~s/\)(.*?)\(|(?<=^[^(])([^($z]*)/ /;$+@eg;s/$/
$s/;$_="@{[split]}
"

Score: 130.47 (pass)

More removal of unnecessary complexity. Thank goodness for $+.

#!perl -p
s/\s//g;s@\(|(?<=[\d)])\D@$z="+-"x$&=~/[(*\/]/;($s="$& $s")=~s/\)(.*?)\(|(?<=^[^(])([^($z]*)/ /;$+@eg;s/$/
$s/;$_="@{[split]}
"

Score: 133.47 (pass)

10-stroke gain, yay! It's nice to get rid of an entire statement.

#!perl -p
s/\s//g;s@\(|(?<=[\d)])\D@$z="+-"x$&=~/[(*\/]/;($s="$& $s")=~s/\)(.*?)\(|^([^(])([^($z]*)/$2 /;$1||$3@eg;s/$/
$s/;$_="@{[split]}
"

Score: 143.52 (pass)

First stab at consolidating the various cases into a single substitution.

#!perl -p
s/\s//g;s@\(|(?<=[\d)])\D@$y=$&eq')'&&'\(';$z="+-"x$&=~/[(*\/]/;($s="$& $s")=~s/^(\)|([^(]))([^($z]*)$y/$2 /;$3@eg;s/$/
$s/;$_="@{[split]}
"

Score: 144.51 (pass)

Replaced [-+*/] with \D, that's pretty much it for now.

#!perl -p
s/\s//g;s@([()])|(?<=[\d)])\D@$s="$& $s";$1?$s=~s/\)(.*?)\(//&&$1:($z="+-"x$&!~/[+-]/,$s=~s/(?<=.)[^($z]*/ /,$&)@eg;s/$/
$s/;$_="@{[split]}
"

Score: 148.48 (pass)

From where I started, I never thought I would get this far, but it's amazing what a whole lot of staring can accomplish.

Looking good

#!perl -p
s/\s//g;s@([()])|(?<=[\d)])([-+])|[*/]@$s="$& $s";$1?$s=~s/\)(.*?)\(//&&$1:($z=!$2&&"+-",$s=~s/(.)([^($z]*)/$1 /,$2)@eg;s/$/
$s/;$_="@{[split]}
"

Score: 153.69 (pass)

Starting to cut down on the parentheses, finally!

#!perl -lp
s/\s//g;s@([()])|(?<=[\d)])([-+])|[*/]@$".($1?($s=$1.$s)=~s/\)(.*?)\(//&&$1:($x=$&,$z=!$2&&"+-",$s=~s/^[^($z]*/$x /,$&))@eg;$_=join$","$_ $s"=~/\S+/g

Score: 160.68 (pass)

Hooray! 12th place at long last! It's mine, all mine!

#!perl -lp
s/\s//g;s@(\()|(\))|(?<=[\d)])([-+])|[*/]@$".($1?$s!~s/^/(/:$2?$s=~s/(.*?)\(//&&$1:($x=$&,$z=!$3&&"+-",$s=~s/^[^($z]*/$x /,$&))@eg;$_=join$","$_ $s"=~/\S+/g

Score: 163.69 (pass)

Slowly inching my way toward 12th place...

#!perl -lp
s/\s//g;s@(\()|(\))|(?<=[\d)])([-+])|[*/]@$".($1?$s!~s/^/(/:$2?$s=~s/(.*?)\(//&&$1:($x=$&,$z=!$3&&"+-",$s=~s/^[^($z]*/$x /,$&)).$"@eg;$_=join$","$_ $s"=~/\S+/g

Score: 166.56 (pass)

Yet a few more strokes shaved...

#!perl -p
s/\s//g;s@(\()|(\))|(?<=[\d)])([-+])|[*/]@$/.($1?!($s="$& $s"):$2?$s=~s/(.*?)\(//&&$1:($x=$&,$z=!$3&&"+-",$s=~s/^[^($z]*/$x /,$&)).$/@eg;$_.="
$s";$_="@{[split]}
"

Score: 171.55 (pass)

A few strokes improvement.

#!perl -p
s/\s//g;s@(\()|(\))|(?<=[\d)])([-+])|[*/]@$/.($1?!($s="$& $s"):$2?$s=~s/(.*?)\(//&&$1:($x=$&,$z=" */".($3&&"+-"),$s=~s/^[$z]*/$x /,$&)).$/@eg;$_.="
$s";$_="@{[split]}
"

Score: 175.40 (pass)

Looking better, but it still feels way too verbose.

Might be verbose, but it's working and you still have a whole week to trim it. Courage!

#!perl -p
s/\s//g;s@(\()|(\))|(?<=[\d)])([-+])|[*/]@$/.($1?($s="$&
$s")&&'':$2?$s=~s/(.*?)\(//s&&$1:($x=$&,$z="
*/".($3&&"+-"),$s=~s/^[$z]*/$x
/,$&)).$/@eg;$_.="
$s";$_="@{[split]}
"

Score: 192.39 (pass)

#!perl -p
s/\s//g;s/(?

Score: 205.77 (pass)

#!perl -ln
s/\s//g;/\d/?push@g,$_:/\)/?($f=pop@s)ne'('&&push(@g,$f)&&redo:(/([+-])|[*\/]/&&($z="*/".($1&&"+-"),"@s"=~/[$z]$/)&&push(@g,pop@s)&&redo,push@s,$_)for/(?:(?

Score: 206.77 (fail)

Fails on (-1 + 2)

#!perl -ln
s/\s//g;/\d/?push@g,$_:/\)/?($f=pop@s)ne'('&&push(@g,$f)&&redo:(/([+-])|[*\/]/&&($z="*/".($1&&"+-"),"@s"=~/[$z]$/)&&push(@g,pop@s)&&redo,push@s,$_)for/(?:(?

Score: 234.76 (fail)

Better, but still a long way to go.

Fails on (-1 + 2)

#!perl -ln
s/\s//g;/\d/?push@g,$_:/\)/?($f=pop@s)ne'('&&push(@g,$f)&&redo:(/[+-]/?"@s"=~/[\*\/+-]$/&&(push(@g,pop@s),redo):/[*\/]/&&"@s"=~/[\*\/]$/&&(push(@g,pop@s),redo),push@s,$_)for/(?:(?

Score: 327.75 (pass)

Holy moly, what an ugly drive. Now to hack my way out of the rough...

#!perl -ln0
s/\s//g;s!(^|[+/*-])-!$1~!g;@t=/[\(\)+\/*-]|~?\d+/g;for(@t){s/~/-/;/\d/?push(@g,$_):/\(/?push(@s,$_):/\)/?${$f=pop@s,($f ne'('&&(push(@g,$f),redo))}:/[+-]/?${$s[-1]=~/[\*\/+-]/&&($f=pop@s,push(@g,$f),redo);push@s,$_}:/[*\/]/?${$s[-1]=~/[\*\/]/&&($f=pop@s,push(@g,$f),redo);push@s,$_}:1}$f=pop@s,push@g,$f while@s;print"@g"