diff --git a/src/ex/q055.clj b/src/ex/q055.clj new file mode 100644 index 0000000..9435648 --- /dev/null +++ b/src/ex/q055.clj @@ -0,0 +1,9 @@ +;; https://4clojure.oxal.org/#/problem/055 + +(ns ex.q055) + +(defn ans + "Problem 55, Count Occurences. special restrictions: frequencies" + [coll] + (let [grouped (group-by identity coll)] + (zipmap (keys grouped) (map count (vals grouped))))) \ No newline at end of file diff --git a/test/ex/q055_test.clj b/test/ex/q055_test.clj new file mode 100644 index 0000000..e85d72c --- /dev/null +++ b/test/ex/q055_test.clj @@ -0,0 +1,10 @@ +;; https://4clojure.oxal.org/#/problem/055 + +(ns ex.q055-test + (:require [clojure.test :as t] + [ex.q055 :as sut])) +(t/deftest test-q55 + (t/testing "Problem 55, Count Occurences" + (t/is (= {1 4, 2 2, 3 1} (sut/ans [1 1 2 3 2 1 1]))) + (t/is (= {:a 2, :b 3} (sut/ans [:b :a :b :a :b]))) + (t/is (= {[1 2] 1, [1 3] 2} (sut/ans '([1 2] [1 3] [1 3])))))) \ No newline at end of file