AoC/2023/day15/day15.hs
2023-12-15 19:33:31 +01:00

33 lines
675 B
Haskell

{-# LANGUAGE LambdaCase #-}
import Debug.Trace
import Data.List
import Text.Read
import Control.Arrow
import Data.List.Split
import qualified Data.Map as M
type HASH = (String, Maybe Int)
main :: IO ()
main = interact $ show . parse . init
parse :: String -> [HASH]
parse = map (second (readMaybe . tail) . break (`elem` "=-")) . splitOn ","
day15a :: String -> Int
day15a = sum . map (foldl' hashAlg 0) . splitOn ","
hashAlg :: Int -> Char -> Int
hashAlg x y = (17 * (fromEnum y + x)) `mod` 256
removeHash :: [HASH] -> HASH -> [HASH]
removeHash hs (s,n) = undefined
f1 n (x,_) = foldl hashAlg 0 x == n
f2 s (x,_) = x==s
-- input <- lines <$> readFile "testinput"