Skip to content

Commit

Permalink
Add q77
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkun committed Sep 22, 2024
1 parent 092ecc2 commit 318bef0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/ex/q077.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
;; https://4clojure.oxal.org/#/problem/077

(ns ex.q077)

(defn ans
"Problem 77, Anagram Finder"
[coll]
(letfn [(hash-word [w] (->> w sort (apply str) hash))]
(set
(filter #(> (count %) 1)
(map set (vals (group-by hash-word coll)))))))
12 changes: 12 additions & 0 deletions test/ex/q077_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
;; https://4clojure.oxal.org/#/problem/077

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

(t/deftest test-q77
(t/testing "Problem 77, Anagram Finder"
(t/is (= #{#{"meat" "team" "mate"}}
(sut/ans ["meat" "mat" "team" "mate" "eat"])))
(t/is (= #{#{"veer" "ever"} #{"lake" "kale"} #{"mite" "item"}}
(sut/ans ["veer" "lake" "item" "kale" "mite" "ever"])))))

0 comments on commit 318bef0

Please sign in to comment.