#!perl -l
chomp($_=<>);$_="($_)";1while s!\(\s*([^(]+?)\)!$a=$1;map{1while$a=~s#((^|[*/+-]\s*)(-))?\s*(\w+)\s*([$_])\s*(-?)\s*(\w+)\s*#$h{A.++$i}="$3$4 $6$7 $5";"$2A$i"#e}'*/','-+';$a!e;1while s|A\d+|$h{$&}|;print
|
#!perl -l
chomp($_=<>);$_="($_)";1while s!\(\s*([^(]+?)\)!$a=$1;map{1while$a=~s#((^|[*/+-]\s*)(-))?\s*([A0-9]+)\s*([$_])\s*(-?)\s*([A0-9]+)\s*#$h{A.++$i}="$3$4 $6$7 $5";$2."A$i"#e}'*/','-+';$a!e;1while s|A\d+|$h{$&}|e;print
|
#!perl -l
chomp($_=<>);$_="($_)";1while s!\(\s*([^(]+?)\)!$a=$1;for$b('*/','-+'){1while $a=~s#((^|[*/+-]\s*)(-))?\s*([A0-9]+)\s*([$b])\s*(-?)\s*([A0-9]+)\s*#$h{A.++$i}="$3$4 $6$7 $5";$2."A$i"#e}$a!e;1while s|A\d+|$h{$&}|e;print
|
at least I'm getting near the ballpark
#!perl -l
chomp($_=<>);$_="($_)";1while s!\(([^(]+?)\)!$a=$1;$a=~s#\s*((^|[*/+-])\s*)-\s*#$1=#g;for$b('*/','-+'){1while$a=~s#\s*(=?[A0-9]+)\s*([$b])\s*(=?[A0-9]+)\s*#$h{A.++$i}="$1 $3 $2";"A$i"#e}$a!xe;1while s|(A\d+)|$h{$1}|e;s/=/-/g;print
|
not sure why I'm bothering to refine this algorithm since I know it can't compete...
#!perl -l
sub g{my$t=pop;$t=~s|\s*((^\|[*/+-])\s*)-\s*|$1=|g;$t=~s|^\s*(-?\d+)\s*$|$h{A.++$i}=$1;"A$i"|ge;for$a('*/','-+'){$t=~s|\s*(=?[A0-9]+)\s*([$a])\s*(=?[A0-9]+)\s*|$h{A.++$i}="$1 $3 $2";"A$i"|ewhile$t=~/[$a]/}$t}chomp($_=<>);s|\(([^()]+)\)|$h{A.++$i}=g$1;"A$i"|gewhile/\(/;$_=g$_;s|(A\d+)|$h{$1}|while/A/;s|=|-|g;print
|
*sigh* ... at least I'm on the board...
#!perl -l
sub g{my$t=pop;$t=~s|\s*((^\|[*/+-])\s*)-\s*|$1=|g;$t=~s|^\s*(-?\d+)\s*$|$h{A.++$i}=$1;"A$i"|ge;$t=~s|\s*(=?[A0-9]+)\s*([*/])\s*(=?[A0-9]+)\s*|;$h{A.++$i}="$1 $3 $2";"A$i"|ewhile$t=~/[*\/]/;$t=~s|\s*(=?[A0-9]+)\s*([+\-])\s*(=?[A0-9]+)\s*|$h{A.++$i}="$1 $3 $2";"A$i"|ewhile$t=~/[+-]/;$t}chomp($_=<>);s|\(([^()]+)\)|$h{A.++$i}=g$1;"A$i"|gewhile/\(/;$_=g$_;s|(A\d+)|$h{$1}|while/A/;s|=|-|g;print
|