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/(?
|
Just a better tie breaker.
#!perl -pl
use
overload'0+',sub{"@{$_[0]}"},nomethod,sub{bless\@_};y/ //d+s/(?
|
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/(?
|
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/(?
|
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/(?
|
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/(?
|
Better tie-breaker.
#!perl -pl
sub
n{my$p=pop;bless\$p}use
overload
nomethod,sub{n"${$_[0]} ${$_[1]} ".pop};y/ //d+s/(?
|
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/(?
|
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/(?
|
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()}
|
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()}
|