Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Add-A-Gram Performance

by patgas (Friar)
on Feb 06, 2002 at 00:10 UTC ( [id://143506]=note: print w/replies, xml ) Need Help??


in reply to Add-A-Gram Performance

You know, I looked at that challenge a couple weeks ago, and thought nothing of it. After all, they're looking for C++ and LISP programmers (I think). It wasn't until this very afternoon that I thought about it again, and started working on it. I had a good start on it before I left work, and I was going to pick back up on it tomorrow. That is, until I read all this. It's like having the ending of a good movie ruined. *sigh* :p

"We're experiencing some Godzilla-related turbulence..."

Replies are listed 'Best First'.
Re (tilly) 2: Add-A-Gram Performance
by tilly (Archbishop) on Feb 06, 2002 at 08:55 UTC
    Hey, they still have the 9 9's problem that nobody has ruined yet.

    Good luck getting it to run in under 1 minute. :-)

      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"; }
      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 :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://143506]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-23 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found