From f2c4afd7b49dc85694d32d080b60a7164027df82 Mon Sep 17 00:00:00 2001 From: KoenDR06 Date: Mon, 1 Dec 2025 11:18:02 +0100 Subject: [PATCH] init + day 1 --- .gitignore | 1 + src/Day2501.hs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 .gitignore create mode 100644 src/Day2501.hs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6b9a1e9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +inputs/ diff --git a/src/Day2501.hs b/src/Day2501.hs new file mode 100644 index 0000000..debf70b --- /dev/null +++ b/src/Day2501.hs @@ -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