aoc2025/sander/AoC 2025

51 lines
2.0 KiB
Plaintext

-- AOC 2025 - Sander
-- so for those wondering about how I run this Haskell code, here's the setup:
-- 1) install GHCup as instructed from https://www.haskell.org/ghcup/
-- 2) save this haskell file and your AOC input file in some directory on your computer
-- 3) rewrite the "main" function with the location of your AOC input file
-- 4) rewrite "print contents" in the "main" function to use the function(s) you've made to process the input file ("contents") from that day correctly
-- 5) run Command Prompt, go to the directory of your files (with "cd" command) and run the command "ghci AOC2025.hs"
-- 6) run command "main"
-- 7) if your functions are correct, you'll get the correct answer!
import System.IO
import Control.Monad
main :: IO()
main = do handle <- openFile "C:/Users/[your directory here]/d1.txt" ReadMode
contents <- hGetContents handle
print (doday1_1 contents)
hClose handle
-- Day 1: ...
-- Part One (not correct yet)
doday1_1 :: String -> String
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
doday1_2 :: String -> String
doday1_2 input = undefined