Skip to content

Commit

Permalink
Simplifiy anagram
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhijit Sarkar committed Sep 8, 2024
1 parent a0aeade commit 289f781
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions anagram/src/Anagram.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ import qualified Data.Char as C
import qualified Data.List as L

anagramsFor :: String -> [String] -> [String]
anagramsFor xs xss = [x | x <- xss, let s = toUpper x, s /= ys && freq s == zs]
anagramsFor xs xss = [x | x <- xss, let s = toUpper x, s /= ys && L.sort s == zs]
where
toUpper = map C.toUpper
ys = toUpper xs
zs = freq ys

toUpper :: String -> String
toUpper = map C.toUpper

freq :: String -> [(Char, Int)]
freq xs = map (\a -> (head a, length a)) $ L.group $ L.sort xs
zs = L.sort ys

0 comments on commit 289f781

Please sign in to comment.