Update sander/AoC 2025
parent
01a11ad970
commit
a2fe8b86ee
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue