Skip to content

Commit

Permalink
Add q55
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkun committed Aug 24, 2024
1 parent 536d1e3 commit 4a1e5cb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/ex/q055.clj
Original file line number Diff line number Diff line change
@@ -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)))))
10 changes: 10 additions & 0 deletions test/ex/q055_test.clj
Original file line number Diff line number Diff line change
@@ -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]))))))

0 comments on commit 4a1e5cb

Please sign in to comment.