module Main where import Data.List (transpose) import Data.Bits (shift, complement, (.&.)) main :: IO () main = interact solution solution :: String -> String solution = show . (\x -> x * (complement x .&. 4095)) . bits_to_number . map mostcommon . transpose . map (map ((read :: String -> Int) . (pure :: a -> [a]))) . lines where mostcommon :: [Int] -> Int mostcommon a = if count 0 a > count 1 a then 0 else 1; count :: Eq a => a -> [a] -> Int count e [] = 0 count e (a:r) = count e r + if a == e then 1 else 0 bits_to_number :: [Int] -> Int bits_to_number = btn' . reverse where btn' :: [Int] -> Int btn' [] = 0 btn' (a:r) = shift (btn' r) 1 + a