Infix to RPN
Score: 103.33 (pass)
#!perl -Xlp
sub
c{($|--&&/\s/*s///g%/^./+/^-*\d+/?$&:c()).pop.($|--?/^[+-]/:s///
x/^[*\/]/and$".c(" $&"))}$_=c
|
Score: 103.34 (pass)
#!perl -Xlp
sub
c{($|--&&s///g%/^./+/^-*\d+/?$&:c()).pop.($|--?/^[+-]/:s///
x/^[*\/]/and$".c(" $&"))}/\s/;$_=c
|
Score: 103.61 (pass)
#!perl -Xlp
sub c{($|--&&s///g%/^./+/^-?\d+/?$&:c()).pop.($|--?/^[+-]/:s/// x/^[*\/]/and$".c(" $&"))}/\s/;$_=c
|
Score: 104.25 (pass)
since i can't seem to find anything big,
let's think small
#!perl -p
sub
c{$|--&&s///-/./+/^-*\d+/?$&+0:c(),@_,($|--?/^[+-]/:s///
x/^[*\/]/and$",c(" $&"))}y/ //d;print
c
|
Score: 104.26 (pass)
almost forgot one more line
#!perl -p
sub
c{$|--&&s///%/./+/^-*\d+/?$&+0:c(),@_,($|--?/^[+-]/:s///
x/^[*\/]/and$",c(" $&"))}y/ //d;print
c
|
Score: 104.30 (pass)
Actually reading the tiebreaker code can be useful
#!perl -p
sub
c{$|--&&s///%/./+/^-*\d+/?$&+0:c(),@_,($|--?/^[+-]/:s///
x/^[*\/]/and$",c(" $&"))}y/ //d;print c
|
Score: 104.57 (pass)
another way to handle the \n
#!perl -p
sub c{$|--&&s///-/./+/^-?\d+/?$&+0:c(),@_,($|--?/^[+-]/:s/// x/^[*\/]/and$",c(" $&"))}y/ //d;print c
|
Score: 104.61 (pass)
Back to a string representation
#!perl -Xlp
sub c{($|--&&s///%/./+/^-?\d+/?$&:c()).pop.($|--?/^[+-]/:s/// x/^[*\/]/and$".c(" $&"))}s/\s//g;$_=c
|
Score: 105.62 (pass)
goodbye overload !
#!perl -lp
sub c{$|--&&s///%/./+/^-?\d+/?"$&":c(),@_,(--$|?s///*/^[*\/]/:/^[+-]/)?c("$&"):()}s/\s//g;$_="@{[c]}"
|
Score: 107.74 (pass)
flog! flog!
#!perl -pibless[s!$!
y/ //d;s/(?
|
Score: 108.61 (pass)
grand unification
#!perl -lp
sub c{--$|?c():s///%/./+/^-?\d+/?"$&":c(),@_,(--$|?s///*/^[*\/]/:/^[+-]/)?c("$&"):()}s/\s//g;$_="@{[c]}"
|
Score: 109.78 (pass)
Still haven't flogged this horse to death
Score: 110.83 (pass)
the code is now completely free of the list of operators, so it will work for the full perl operator set
Score: 111.75 (fail)
#!perl -p
s#(^|[*-/(])\s*(-?\s*\d+)#$1(bless[s!\$! $2!])#g;s/.?/"use overload '$&',sub{s!! $&!;shift}"/gee;eval$`;s///
|
Score: 113.75 (fail)
more regex repeating
#!perl -p
s#(^|[*-/(])\s*(-?\s*\d+)#$1(bless[s!\$! $2!])#g;eval"$_;".s/./"use overload '$&',sub{s!! $&!;shift}"/gee;s///
|
Score: 114.68 (pass)
mm, recursive descent is running out of breath
#!perl -lp
sub a{join$",f(),@_,/^[+-]/?a("$&"):()}sub f{s///;/./;/^-?\d+/?"$&":a,@_,s///*m!^[*/]!?f("$&"):()}s/\s//g;$_=a
|
Score: 114.77 (pass)
#!perl -lp
s/\s//g;s#(^|[*-/(])(-?\d+)#$1(bless[s!\$!$2 !])#g;s/.?/"use overload '$&',sub{s!!$& !;shift}"/gee;eval$`;chop
|
Score: 115.73 (pass)
Sigh. Sacrifise more characters
#!perl -p
s#(^|[*-/(])\s*(-?)\s*(\d+)#$1(bless[s!\$! $2$3!])#g;s/.?/"use overload '$&',sub{s!! $&!;shift}"/gee;eval$`;s///
|
Score: 115.76 (fail)
The output returned for '1 - - 2' is '1 - 2', but it should be something like '1 -2 -'
#!perl -p
s#(^|[*-/(])\s*(-?\s*\d+)#$1(bless[s!\$! $2!])#g;eval"$_;".s/./"use overload '$&',sub{s!\$! $&!;shift}"/gee;s///
|
Score: 116.78 (fail)
mm, the horse still is not dead
#!perl -lp
s#(^|[*-/(])\s*(-?\s*\d+)#$1(bless[s!\$!$2 !])#g;eval"$_;".s/./"use overload '$&',sub{s!\$!$& !;shift}"/gee;chop
|
Score: 121.69 (pass)
Back to playing with a real parser
#!perl -Xlp
sub f{(s/^-?\d+//?$&:a(!s/.//).!s///).pop.(s!^[*/]!!&&$".f(" $&"))}sub a{f.pop.(s/^[+-]//&&$".a($".$&))}s/\s//g;$_=a
|
Score: 128.78 (fail)
Mmm, i'm starting to doubt this horse
Unfortunaty (again), it fails the test with '1 - -\t2'.
#!perl -lp
s#(^|[-+*/(])\s*(-?\d+)#$1(bless[\$q.="$2 "])#g;s/./"use overload'$&',sub{\$q.='$& ';shift}"/eegfor$q="+-*/";eval;$_=$q;chop
|
Score: 129.76 (pass)
Ok, I broke down and wrote an actual parser
Let's start with recursive descent
#!perl -Xlp
sub n{/\G-?\d+/cg?$&:!/./g.&a.!//g}sub f{n.pop.(m!\G[*/]!cg&&$".f(" $&"))}sub a{f.pop.(/\G[+-]/cg&&$".a($".$&))}s/\s//g;$_=a
|
Score: 140.77 (fail)
Unfortunaly, it fails the test with '1 - -\t2'.
#!perl -pl
s/./,"$&",sub{bless["\@_$&"]}/gfor$a="+-*/";s#(^\s*|[-+*/(]\s*)(-?\d+)#$1(bless["$2"])#g;s/^/use overload'""',sub{\$_[0][0]}$a;/;$_=eval
|
Score: 818.00 (fail)
#!perl -wle 'print $_$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$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