Next submission on a different horse. Promise!
#!perl -pl
s/\s//g;%p=qw|* 2 / 2 + 1 - 1|;/\d/?push@_,$_:/\(/?push@@,$_:/\)/?do{push@_,$*while'('ne($*=pop@@)}:do{push@_,pop@@while$p{$@[-1]}>=$p{$_};push@@,$_}for/(?<=[\d)])[*\/+-]|-?\d+|./g;@_=(@_,reverse@@);$_="@_"
|
dead horse, I know. At least I'm ahead of /-\ ;)
#!perl -pl
%p=qw|* 2 / 2 + 1 - 1|;s/\s//g;/\d/?push@_,$_:/\(/?push@@,$_:/\)/?do{push@_,$*while@@&&'('ne($*=pop@@)}:do{push@_,pop@@while$p{$@[-1]}>=$p{$_};push@@,$_}for/(?<=[\d)])[*\/+-]|-?\d+|./g;push@_,pop@@while@@;$_="@_"
|
As usual, start with the brute force approach.
#!perl -pl
%p=qw|* 2 / 2 + 1 - 1|;s/\s//g;map{/\d/?push@_,$_:/\(/?push@@,$_:/\)/?do{push@_,$*while@@&&'('ne($*=pop@@)}:do{push@_,pop@@while$p{$@[-1]}>=$p{$_};push@@,$_}}m:\b[*/+-]|(?<=\))[*/+-]|-?\d+|.:g;push@_,pop@@while@@;$_="@_"
|