AoC/2022/day03/day03.hs
2022-12-03 19:05:28 +01:00

19 lines
493 B
Haskell

import Data.List
import Data.List.Split
import Control.Arrow
import Control.Lens
main :: IO ()
main = do
input <- lines <$> readFile "input"
print $ both %~ sum $ (day3a &&& day3b) input
day3a :: [String] -> [Int]
day3a = map $ convert . uncurry intersect . (both %~ nub) . (flip splitAt <*> flip div 2 . length)
day3b :: [String] -> [Int]
day3b = map (convert . foldl1 intersect) . chunksOf 3
convert :: String -> Int
convert = (\x->if x>90 then x - 96 else x - 38) . fromEnum . head