Wednesday 14 November 2012

Just the Squares Continued

Yes, putting that function together in a different way:-

(def just-squares
  (fn [s]
    (let [split-string (fn [s] (clojure.string/split s #",")),
      join-strings (fn [ss] (clojure.string/join "," ss)),
      square? (fn [n] (let [root (int (. Math sqrt n))] (= (* root root) n))),
      filter-squares (fn [ns] (filter square? ns)),
      strs->ints (fn [ss] (map #(. Integer parseInt %) ss)),
      ints->strs (fn [ns] (map str ns))]
      (-> s split-string strs->ints filter-squares ints->strs join-strings))))


No comments:

Post a Comment