After the sixth round, five more 4clojure.com solutions:
;;; Problem 55 - Count Occurrences (deftest test-problem-55 (let [v1 (fn [xs] (reduce (fn [a v] (assoc a v (inc (get a v 0)))) {} (vec xs))) __ v1] (is (= (__ [1 1 2 3 2 1 1]) {1 4, 2 2, 3 1})) (is (= (__ [:b :a :b :a :b]) {:a 2, :b 3})) (is (= (__ '([1 2] [1 3] [1 3])) {[1 2] 1, [1 3] 2})))) ;;; Problem 54 - Partition a Sequence (deftest test-problem-54 (let [v1 (fn [n xs] (loop [a [] r xs] (if (< (count r) n) a (recur (conj a (take n r)) (drop n r))))) __ v1] (is (= (__ 3 (range 9)) '((0 1 2) (3 4 5) (6 7 8)))) (is (= (__ 2 (range 8)) '((0 1) (2 3) (4 5) (6 7)))) (is (= (__ 3 (range 8)) '((0 1 2) (3 4 5)))))) ;;; Problem 53 - Longest Increasing Sub-Seq (deftest test-problem-53 (let [subseqs #(take-while not-empty (iterate (partial rest) %)) filter2 (fn [f xs] (loop [ll (first xs) l [ll] [fr :as r] (rest xs)] (if (or (nil? ll) (nil? fr) (not (f ll fr))) l (recur fr (conj l fr) (rest r))))) do-run #(map (partial filter2 <) %) do-long (partial filter #(> (count %) 1)) do-sort (partial sort-by #(-' (count %))) v1 #(-> % subseqs do-run do-long (conj []) do-sort first) __ v1] (is (= (__ [1 0 1 2 3 0 4 5]) [0 1 2 3])) (is (= (__ [5 6 1 3 2 7]) [5 6])) (is (= (__ [2 3 3 4 5]) [3 4 5])) (is (= (__ [7 6 5 4]) [])))) ;;; Problem 52 - Intro to Destructuring (deftest test-problem-52 (is (= [2 4] (let [[a b c d e f g] (range)] )))) ;;; Problem 51 - Advanced Destructuring (deftest test-problem-51 (let [v1 [1 2 3 4 5] __ v1] (is (= [1 2 [3 4 5] [1 2 3 4 5]] (let [[a b & c :as d] __] [a b c d]))))) (run-tests)