From a2fe8b86ee1d4f685bdc0376c148cbbc313e272c Mon Sep 17 00:00:00 2001 From: Sander Date: Mon, 1 Dec 2025 21:51:57 +0000 Subject: [PATCH] Update sander/AoC 2025 --- sander/AoC 2025 | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/sander/AoC 2025 b/sander/AoC 2025 index b01296c..a92028c 100644 --- a/sander/AoC 2025 +++ b/sander/AoC 2025 @@ -15,15 +15,34 @@ import Control.Monad main :: IO() main = do handle <- openFile "C:/Users/[your directory here]/d1.txt" ReadMode contents <- hGetContents handle - print contents + print (doday1_1 contents) hClose handle -- Day 1: ... --- Part One +-- Part One (not correct yet) doday1_1 :: String -> String -doday1_1 input = undefined +doday1_1 input = show (countZeroRotations (words input) 50) + +countZeroRotations :: [String] -> Int -> Int +countZeroRotations [] _ = 0 +countZeroRotations (x : xs) pos = countZeroRotations xs (fst (rotateDial x pos)) + snd (rotateDial x pos) + +rotateDial :: String -> Int -> (Int, Int) +rotateDial (direction : r) pos + | direction == 'L' && newposl == 0 = (normalizeHundred newposl, 1) + | direction == 'L' = (normalizeHundred newposl, 0) + | direction == 'R' && newposr == 0 = (normalizeHundred newposr, 1) + | direction == 'R' = (normalizeHundred newposr, 0) + where newposl = normalizeHundred (pos - (read r)) + newposr = normalizeHundred (pos + (read r)) + +normalizeHundred :: Int -> Int +normalizeHundred x + | x >= 100 = x - 100 + | x < 0 = x + 100 + | True = x -- Part Two