this repo has no description
1module Main where
2
3import Data.List.Split
4import qualified Data.Sequence as S
5
6jumpsOutInXSteps :: Int -> Int -> S.Seq Int -> Int
7jumpsOutInXSteps steps pos ints
8 | pos < 0 || pos >= (S.length ints) = steps
9 | otherwise = let jump = S.index ints pos
10 newList = if jump > 2 then S.update pos (jump - 1) ints
11 else S.update pos (jump + 1) ints
12 newPos = (+) pos jump
13 in jumpsOutInXSteps (steps + 1) newPos newList
14
15main :: IO ()
16main = do
17 inputStr <- readFile "input.txt"
18 let input = map (\l -> read l :: Int) . splitOn "\n" $ init inputStr
19 answer = jumpsOutInXSteps 0 0 $ S.fromList input
20 in print answer