day15 WIP

This commit is contained in:
Gattix 2023-12-15 19:33:31 +01:00
parent be88678e6a
commit 2b6d44b137
3 changed files with 34 additions and 0 deletions

32
2023/day15/day15.hs Normal file
View File

@ -0,0 +1,32 @@
{-# 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"

1
2023/day15/input Normal file

File diff suppressed because one or more lines are too long

1
2023/day15/testinput Normal file
View File

@ -0,0 +1 @@
rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7