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
|
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
|
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
|
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
|
Who knew you could interpolate $" as "$\""? Strange...
#!perl -lp
y/ //d+s@\(|(?<=[\d)])\D@($"=" $& $\"")=~s!\)(.*?)\(|([^ (])([ */${':'x/\G[+-]/}]*)!$2 !;$+@eg;$_.=$";y/ //s+chop
|
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/ $//
|
Inline, inline, inline.
#!perl -lp
y/ //d+s@\(|(?<=[\d)])\D@($s=" $& $s")=~s!\)(.*?)\(|([^ (])([ */${':'x/\G[+-]/}]*)!$2 !;$+@eg;$_.=$s;y/ //s+s/ $//
|
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/ $// |
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/ $// |
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 |
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/ $// |
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]}
"
|
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]}
"
|
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]}
"
|
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]}
"
|
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]}
"
|
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]}
"
|
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]}
"
|
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]}
"
|
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]}
"
|
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]}
"
|
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 |
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 |
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 |
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]}
"
|
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]}
"
|
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]}
"
|
#!perl -p s/\s//g;s/(? |
#!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/(?:(?
|
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/(?:(?
|
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/(?:(?
|
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"
|