code corresponding to a coding contest posted here: http://blog.regehr.org/archives/909