Created
December 6, 2020 11:34
-
-
Save mjgpy3/fc4b1a593aed26c25f6445fa3f5a48be to your computer and use it in GitHub Desktop.
aoc-2020-day6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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