solve: day 6, part 2 - bitwise
This commit is contained in:
parent
e40944b22d
commit
2afe23eb00
1 changed files with 17 additions and 0 deletions
17
2020/06/part2_bits.hs
Executable file
17
2020/06/part2_bits.hs
Executable 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
|
Loading…
Reference in a new issue