I had written one of these in python as a code challenge, not my choice. The python seemed very klunky to me after spending so much time doing clojure. So I wrote this one to see how long it would take and what the code would be like. It took an hour, and it is fully tested. The integrated solution worked the first time. It was very satisfying. I do wonder if there is a more elegant solution, particularly for the last bit.