Dec. 4th, 2009 [entries|reading|network|archive]
simont

[ userinfo | dreamwidth userinfo ]
[ archive | journal archive ]

Fri 2009-12-04 09:21
Better testing through Google

The other day I needed a lot of primes in a hurry, and I judged that it would be quicker just to sit down and write a simple Sieve of Eratosthenes program from memory than to faff about trying to google up one that somebody had already written and that wasn't in some unhelpful language.

So I wrote one; then I disposed of the obvious bugs by checking its output rigorously for numbers up to 10; then I ran it for numbers up to 100 and didn't see anything obviously wrong (though I didn't look that hard). Then I wondered whether there was any good way to be more confident of its correctness.

On a whim, I made it generate all the primes up to 2^32, and fed the output text file to md5sum (with Unix line endings). Then I pasted the resulting checksum into Google – and found a hit! Somebody else had generated the same set of primes, checksummed them in exactly the same way, and posted the MD5 on a web forum which was talking about prime-generating programs so that other people on the forum could use it as a test case. Just the confirmation I wanted.

The silly thing is that if I'd tried to google for things like ‘md5sum of primes up to 2^32’, it wouldn't have been remotely successful. But once you already know what you think the answer is (at least in cases where it's a mess of digits), googling for that will tell you whether anyone else agreed with you.

Link7 comments | Reply
navigation
[ viewing | December 4th, 2009 ]
[ go | Previous Day|Next Day ]