For reference, Keith's referring to a solution I wrote up and sent to him privately. The solution is on a private gist.github.com, since I want to avoid posting complete Project Euler solutions on a public forum. If you're interested, you can email me privately. Be well!