Translating a very cool algorithm thought up by the ** Ha**milton **Mi**ddle **Ma**th teachers.  Not sure why I didn't include "te."