-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay5.hs
29 lines (23 loc) · 780 Bytes
/
Day5.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{-# LANGUAGE TupleSections #-}
module Day5
( part1
, part2
) where
import Data.List as L (unfoldr)
import Data.Sequence as S (Seq, adjust', fromList, lookup)
jump :: (Int -> Int) -> (Int, Seq Int) -> Maybe ((), (Int, Seq Int))
jump op (pointer, offsets) =
((), ) . (, newOffsets) . (+) pointer <$> newPointer
where
newPointer = S.lookup pointer offsets
newOffsets = adjust' op pointer offsets
stranger :: Int -> Int
stranger things
| things < 3 = things + 1
| otherwise = things - 1
part1 :: Bool -> String -> String
part1 _ =
show . length . unfoldr (jump (+ 1)) . (0, ) . fromList . map read . lines
part2 :: Bool -> String -> String
part2 _ =
show . length . unfoldr (jump stranger) . (0, ) . fromList . map read . lines