Simple solution in Clojure, with a couple of tests