parent
324e47c7b4
commit
04dd9843db
4 changed files with 2131 additions and 1 deletions
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,27 @@ |
|||||||
|
module Day6 (day6) where |
||||||
|
|
||||||
|
import Data.List (foldl', intersect) |
||||||
|
import qualified Data.Set as S |
||||||
|
|
||||||
|
separateForms :: [String] -> [[String]] |
||||||
|
separateForms s = let (a, b) = foldl' go ([], []) s in b ++ [a] |
||||||
|
where |
||||||
|
go (l, t) "" = ([], t ++ [l]) |
||||||
|
go (l, t) xs = (l ++ [xs], t) |
||||||
|
|
||||||
|
countYesses :: [String] -> Int |
||||||
|
countYesses = length . S.fromList . concat |
||||||
|
|
||||||
|
countYesses' :: [String] -> Int |
||||||
|
countYesses' = length . foldl' go ['a' .. 'z'] |
||||||
|
where |
||||||
|
go b a = b `intersect` a |
||||||
|
|
||||||
|
day6 :: IO () |
||||||
|
day6 = do |
||||||
|
r <- readFile "./input/day6" |
||||||
|
let m = separateForms . lines $ r |
||||||
|
putStr "[Day 6-1] # yess: " |
||||||
|
print . sum . map countYesses $ m |
||||||
|
putStr "[Day 6-2] # yess: " |
||||||
|
print . sum . map countYesses' $ m |
Loading…
Reference in new issue