Day 4

To start this day off, we copy our little parser from day 4, but we don’t need all the parsing logic. We can just treat each answer set as a list of String, because each String represents a single person’s answers.

answers :: String -> [[String]]
answers = splitOn [""] . lines

For part A, we just want to count the number of unique answers. This is commonly done via length . group . sort. For part B, we need to filter out the answers with the incorrect amount of responses. The number of people is just given by length :: [String] -> Int, so we want to filter each group of answers with \g -> length g == length a. Our final code then looks like

solve006 :: String -> Bool -> String
solve006 i b = show . sum $ f <$> answers i
  where f a = length . filter (g a) . group . sort . concat $ a
        g a = if b then
                (==(length a)) . length
              else
                const True