6 text <- readFile "data/advent02.txt"
11 part1 ids = (fst counts23) * (snd counts23)
12 where allLetterCounts = map letterCounts ids
13 counts23 = foldl' addCounts (0, 0) allLetterCounts
15 letterCounts :: String -> [Int]
16 letterCounts = map length . group . sort
18 addCounts :: (Int, Int) -> [Int] -> (Int, Int)
19 addCounts (twos, threes) counts = (twos', threes')
20 where twos' = if has2 counts then twos + 1 else twos
21 threes' = if has3 counts then threes + 1 else threes
26 part2 ids = uncurry sameChars closeIds
27 where closeIds = head $ filter (\ab -> uncurry differenceCount ab == 1) [(a, b) | a <- ids, b <- ids]
29 differenceCount :: String -> String -> Int
30 differenceCount this that = length $ filter (\(a, b) -> a /= b) $ zip this that
32 sameChars :: String -> String -> String
33 sameChars this that = map fst $ filter (\(a, b) -> a == b) $ zip this that