Why doesn't part 2 work?

This commit is contained in:
2025-12-01 08:34:06 +01:00
parent 1ff5cb8d55
commit 4cd107bf22
3 changed files with 4719 additions and 13 deletions

View File

@ -1,6 +1,41 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
module Main where
import Data.Functor
data Rotation where
RRight :: Int -> Rotation
RLeft :: Int -> Rotation
parse :: String -> [Rotation]
parse = map (\case
('R':xs) -> RRight (read xs :: Int)
('L':xs) -> RLeft (read xs :: Int)
_ -> error "") . lines
solver :: Bool -> [Rotation] -> Int
solver b = go 50
where go :: Int -> [Rotation] -> Int
go _ [] = 0
go curr (RRight n : xs) =
let (rots,newCurr) = bound (curr + n) in
(if | b -> (rots+)
| newCurr == 0 -> (1+)
| otherwise -> id) $ go newCurr xs
go curr (RLeft n : xs) =
let (rots,newCurr) = bound (curr - n) in
(if | b -> (rots+)
| newCurr == 0 -> (1+)
| otherwise -> id) $ go newCurr xs
bound :: Int -> (Int,Int)
bound x
| x < 0 = (\(n,y) -> (n+1,y)) . bound $ x + 100
| x > 99 = (\(n,y) -> (n+1,y)) . bound $ x - 100
| otherwise = (0, x)
main :: IO ()
main = pure ()
main = readFile "inputs/1" <&> parse >>= \i ->
print (solver False i) >>
print (solver True i)