From bbd4254ce879d7c22721f8f560e41f609bd837e8 Mon Sep 17 00:00:00 2001 From: Zach Perrault <zach@perrault.email> Date: Sun, 6 Dec 2020 12:05:40 -0500 Subject: [PATCH] solve: day 6, part 2 - bitwise --- 2020/06/part2_bits.hs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 2020/06/part2_bits.hs diff --git a/2020/06/part2_bits.hs b/2020/06/part2_bits.hs new file mode 100755 index 0000000..fac165f --- /dev/null +++ b/2020/06/part2_bits.hs @@ -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