I think my cat is plotting against me.

Update, 7 PM The prime number shitting bear has scalability issues. Mine is up to half a million. I have it on my Active Desktop. It chews up 80% of my CPU, until it shits, at which point it drops to 20%. I’ve examined the JavaScript source and some optimizations leap to mind. Currently the time requirements are O(n) and the space requirements are O(1). But you only need to check for divisibility up to and including the square root of the number, which would decrease the time requirements to O(sqrt(n)). You could also limit to checking for divisibility of previously-shit primes, but this has the unfortunate consequence of increasing the space requirements to some magnitude > 1 (in other words, the bear would consume an ever-increasing amount of memory the more primes it shit). Alternatively, you could change the algorithm completely and make the bear shit random primes instead of consecutive primes; in theory, this could be O(1) for both time and space. There are many algorithms to generate random primes; here’s one called the Rabin-Miller test, which should tickle the funny bone of someone I know named Rabin who reads this weblog. (I also know someone named Miller, but she does not, as far as I know, read this weblog. She was a math major, though, so she probably knows more than I do about how to shit primes efficiently.)

§

Respond privately

I am no longer accepting public comments on this post, but you can use this form to contact me privately. (Your message will not be published.)



§

firehosecodemusicplanet

© 2001–8 Mark Pilgrim