1
0
Fork 0

solve: day 6, part 2 - bitwise

This commit is contained in:
Zach Perrault 2020-12-06 12:05:40 -05:00
parent 280592563c
commit bbd4254ce8
No known key found for this signature in database
GPG key ID: D59F59045E12F0F5

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