init + day 1

This commit is contained in:
KoenDR06 2025-12-01 11:18:02 +01:00
commit f2c4afd7b4
2 changed files with 23 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
inputs/

22
src/Day2501.hs Normal file
View file

@ -0,0 +1,22 @@
module Main where
part1 :: String -> Int
part1 = length . dropNonZero . scanl (+) 50 . convertToInts . lines
where
convertToInts = map (\it -> (if head it == 'L' then -1 else 1) * read (drop 1 it))
dropNonZero = filter ((0==) . (`mod` 100))
part2 :: String -> Int
part2 = length . dropNonZero . scanl (+) 50 . makeSingleSteps . convertToInts . lines
where
convertToInts = map (\it -> (if head it == 'L' then -1 else 1) * read (drop 1 it))
dropNonZero = filter ((0==) . (`mod` 100))
makeSingleSteps = concatMap (\it -> replicate (abs it) (signum it))
main :: IO ()
main = do
str <- readFile "inputs/2025-1"
print $ part1 str
print $ part2 str