After cheating a bit...

This commit is contained in:
2025-12-01 08:58:46 +01:00
parent 4cd107bf22
commit 02ee5cb935

View File

@ -20,20 +20,23 @@ solver b = go 50
go _ [] = 0 go _ [] = 0
go curr (RRight n : xs) = go curr (RRight n : xs) =
let (rots,newCurr) = bound (curr + n) in let (rots,newCurr) = bound (curr + n) in
(if | b -> (rots+) (if | b -> (rots +)
| newCurr == 0 -> (1+) | newCurr == 0 -> (1+)
| otherwise -> id) $ go newCurr xs | otherwise -> id) $
go newCurr xs
go curr (RLeft n : xs) = go curr (RLeft n : xs) =
let (rots,newCurr) = bound (curr - n) in let (rots,newCurr) = bound (curr - n) in
(if | b -> (rots+) (if | b -> (rots - (if curr == 0 then 1 else 0) +)
| newCurr == 0 -> (1+) | newCurr == 0 -> (1+)
| otherwise -> id) $ go newCurr xs | otherwise -> id) $
go newCurr xs
bound :: Int -> (Int,Int) bound :: Int -> (Int,Int)
bound x bound x
| x < 0 = (\(n,y) -> (n+1,y)) . bound $ x + 100 | x < 0 = (\(n,y) -> (n+1,y)) . bound $ x + 100
| x > 99 = (\(n,y) -> (n+1,y)) . bound $ x - 100 | x == 0 || x == 100 = (1,0)
| otherwise = (0, x) | x > 99 = (\(n,y) -> (n+1,y)) . bound $ x - 100
| otherwise = (0, x)
main :: IO () main :: IO ()
main = readFile "inputs/1" <&> parse >>= \i -> main = readFile "inputs/1" <&> parse >>= \i ->