Skip to content

Commit

Permalink
Add q56
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkun committed Aug 24, 2024
1 parent 4a1e5cb commit 627ece9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/ex/q056.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
;; https://4clojure.oxal.org/#/problem/056

(ns ex.q056)

(defn ans
"Problem 56, Find Distinct Items. restrictions: distinct"
[coll]
(let [seen (atom #{})]
(into [] (filter #(if (contains? @seen %) false (do (swap! seen conj %) true)) coll))))
12 changes: 12 additions & 0 deletions test/ex/q056_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
;; https://4clojure.oxal.org/#/problem/056

(ns ex.q056-test
(:require [clojure.test :as t]
[ex.q056 :as sut]))

(t/deftest test-q56
(t/testing "Problem 56, Find Distinct Items"
(t/is (= [1 2 3 4] (sut/ans [1 2 1 3 1 2 4])))
(t/is (= [:a :b :c] (sut/ans [:a :a :b :b :c :c])))
(t/is (= '([2 4] [1 2] [1 3]) (sut/ans '([2 4] [1 2] [1 3] [1 3]))))
(t/is (= (range 50) (sut/ans (range 50))))))

0 comments on commit 627ece9

Please sign in to comment.