Initial commit

This commit is contained in:
Dimitri Lozeve 2024-11-12 21:43:32 +01:00
commit f242d2b0df
420 changed files with 62521 additions and 0 deletions

38
2017/09/day9.hs Normal file
View file

@ -0,0 +1,38 @@
#!/usr/bin/env stack
-- stack --resolver lts-9.17 script
import Data.List
data Stream = Stream
{ depth :: Int
, score :: Int
, ignoreNextChar :: Bool
, garbage :: Bool
, countGarbage :: Int
} deriving (Show, Eq)
processChar :: Stream -> Char -> Stream
processChar stream c =
if ignoreNextChar stream then
stream { ignoreNextChar = False }
else if garbage stream then
case c of
'!' -> stream { ignoreNextChar = True }
'>' -> stream { garbage = False }
_ -> stream { countGarbage = countGarbage stream + 1 }
else if c == '}' then
stream { depth = depth stream - 1, score = score stream + depth stream }
else if c == '{' then
stream { depth = depth stream + 1 }
else if c == '<' then
stream { garbage = True }
else stream
processStream :: String -> Stream
processStream = foldl' processChar (Stream 0 0 False False 0)
main :: IO ()
main = do
stream <- processStream <$> getContents
putStrLn . show $ score stream
putStrLn . show $ countGarbage stream

1
2017/09/input.txt Normal file

File diff suppressed because one or more lines are too long