Skip to content

Instantly share code, notes, and snippets.

@mjgpy3
Created December 6, 2020 11:34
Show Gist options
  • Save mjgpy3/fc4b1a593aed26c25f6445fa3f5a48be to your computer and use it in GitHub Desktop.
Save mjgpy3/fc4b1a593aed26c25f6445fa3f5a48be to your computer and use it in GitHub Desktop.
aoc-2020-day6
{-# LANGUAGE OverloadedStrings #-}
module Main where
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
import Data.List.NonEmpty (groupAllWith)
groups = map (T.replace "\n" "") . T.splitOn "\n\n"
distinctAnswerCount = length . groupAllWith id . T.unpack
main = do
raw <- TIO.readFile "./d6.txt"
print $ sum $ map distinctAnswerCount $ groups raw
{-# LANGUAGE OverloadedStrings #-}
module Main where
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
import Data.List.NonEmpty (groupAllWith)
import Data.Bifunctor
dupe a = (a, a)
groups = map countPeopleJoinAnswers . T.splitOn "\n\n" . T.strip
where
countPeopleJoinAnswers = bimap ((+ 1) . T.count "\n") (T.replace "\n" "") . dupe
allAnswered =
concatMap $ uncurry (filter . (==)) . second (map length . groupAllWith id . T.unpack)
main = do
raw <- TIO.readFile "./d6.txt"
print $ length $ allAnswered $ groups raw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment