1
0
Fork 0

solve: day 6, part 2 - bitwise

This commit is contained in:
Sloane Perrault 2022-09-21 09:19:52 -04:00
parent e40944b22d
commit 2afe23eb00

17
2020/06/part2_bits.hs Executable file
View file

@ -0,0 +1,17 @@
#!/usr/bin/env runghc
import Day6
import Data.Bits
import Data.Char
main = interact (show . solve . lines')
solve = sum . map countEveryoneYes
charToBit c = bit $ ord c - ord 'a'
stringToBits :: String -> Int
stringToBits str = foldl1 (.|.) $ map charToBit str
countEveryoneYes group = popCount $ foldl1 (.&.) $ map stringToBits group