My solutions to Advent of Code 2021
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
|
|
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
|