Infix to RPN

Score: 115.47 (fail)

We don't need to make the constructor explicit. WARNING: Like my last program, this uses a lot of memory. Maybe even more than my last program.

The memory usage is problematic, but it seems that even with the full 4 GB (allowed by the rules) of real memory this would be way too slow.

#!perl -p
use
overload
nomethod,sub{bless[@{$_[0]},@{$_[1]},pop]};y/ 	//d+s/(?

Score: 116.65 (pass)

Just a better tie breaker.

#!perl -pl
use
overload'0+',sub{"@{$_[0]}"},nomethod,sub{bless\@_};y/ 	//d+s/(?

Score: 116.66 (fail)

While my rude 115.47 is still pending, try this one, which is one stroke longer, but much more polite.

This has now taken 15 minutes of CPU on a 750 MHz Athlon, which isn't swapping. Sorry, but I'll have to reject the solution.

#!perl -pl
use
overload'""',sub{"@{$_[0]}"},nomethod,sub{bless\@_};y/ 	//d+s/(?

Score: 116.66 (pass)

One shot worse than my 115.47 solution, but shouldn't use so much memory or time!

Sorry about the erronous rejection.

#!perl -pl
use
overload'""',sub{"@{$_[0]}"},nomethod,sub{bless\@_};y/ 	//d+s/(?

Score: 118.45 (pass)

Save a lot of strokes in the constructor by using arrays instead of scalars as the objects. WARNING: Uses a lot of memory for the final test. It does complete within the memory and speed constraints though.

#!perl -p
sub
n{bless\@_}use
overload
nomethod,sub{n@{$_[0]},@{$_[1]},pop};y/ 	//d+s/(?

Score: 126.50 (pass)

Save two strokes by building a string inside the constructor instead of inside the overloaded operator.

#!perl -pl
sub
n{my$p="@_";bless\$p}use
overload
nomethod,sub{n${$_[0]},${$_[1]},pop};y/ 	//d+s/(?

Score: 128.49 (pass)

Better tie-breaker.

#!perl -pl
sub
n{my$p=pop;bless\$p}use
overload
nomethod,sub{n"${$_[0]} ${$_[1]} ".pop};y/ 	//d+s/(?

Score: 128.52 (pass)

Another stroke bites the dust.

#!perl -pl
sub
n{my$p=pop;bless\$p}use
overload
nomethod,sub{n"${$_[0]} ${$_[1]} ".pop};y/ 	//d+s/(?

Score: 129.52 (pass)

Cheaper to handle unary minus ourselves.

And BoB is beaten 7,5 hours after the rules were available .. impressive

#!perl -pl
sub
n{my$p=pop;bless\$p}use
overload
nomethod,sub{n"${$_[0]} ${$_[1]} ".pop};y/ 	//d+s/(?

Score: 140.47 (pass)

Minor improvements

#!perl -pl
sub
n{my$p=pop;bless\$p}use
overload
nomethod,sub{n$_[3]lt
9?"${$_[0]} ${$_[1]} ".pop:"-${$_[0]}"};s/-/
-/g+s/\d+/(n"$&")/g;$_=${eval()}

Score: 141.50 (pass)

Let Perl sort it out.

That's very cool!

#!perl -pl
sub
n{my$p=pop;bless\$p}use
overload
nomethod,sub{n$_[3]lt 9?"${$_[0]} ${$_[1]} $_[3]":"-${$_[0]}"};s/-/
-/g;s/\d+/(n"$&")/g;$_=${eval()}