| [reply] |
use Quantum::Superpositions;
$nines[1] = any(9);
for $i ( 1..8 ){
$nines[$i+1] = any eigenstates any map{
$nines[$_]+$nines[$i-$_+1],
$nines[$_]-$nines[$i-$_+1],
$nines[$_]*$nines[$i-$_+1],
$nines[$_]/any grep{$_!=0}eigenstates $nines[$i-$_+1]
} 1..$i;
print $nines[$i+1],"\n";
for( $_=1;;$_++){ last unless $_ eq $nines[$i+1] }
print "$_\n";
}
| [reply] [d/l] |
Hey, they still have the 9 9's problem that nobody has ruined yet.
Good luck getting it to run in under 1 minute. :-)
Well, I got it running in about one hour (on my ancient 200MHz 486), which is better
than the few days I thought it was going to take at first :-)
(So if I run it on some new fangled 12Ghz system, it might break a minute, right? ;-)
What matters, of course, is how many iterations it takes, and what it came down to (in my solution) was how many ways to order
the 4 operators eight in a row (4**8 => 65536), times how
many ways to put 9 duplicate balls in eight different buckets (which is alot, until I realized each bucket
only needs to hold at most two balls, and then I filtered most of the redundant and invalid combinations from that which resulted in only 64
combinations), which resulted in about 4 million iterations
of the main loop.
I'm not going to spoil the answer here (and I hope
I haven't given away too much already, and only provoke
"what the hell is he talking about?" responses from most
people), since the add-a-gram has been done to death both here and on comp.lang.perl.misc, and I'd hate to see the same done to
the 9 nines, but anyone that can filter the problem space
even further has my ++'s...(hmm, wonder if I can get a job
in Cambridge, MA now...)
Update: Damn! While I took a completely different
approach, it'll never beat tilly's (and I suppose its
not even worth pointing out that my implementation was
broken, and that the corrected version will take about
2 hours to run :-)
| [reply] |
| [reply] |