@@ -13,20 +13,10 @@ split x (y:ys) | x == y = [] : split x ys
13
13
in (y : y') : ys'
14
14
split _ [] = [[] ]
15
15
16
- -- | Finds the period of the given function.
17
- period :: Ord a => (a -> a ) -> a -> [a ]
18
- period f = period' S. empty
19
- where period' acc x | x `S.member` acc = []
20
- | otherwise = x : period' (S. insert x acc) (f x)
21
-
22
16
-- | The cartesian product with itself.
23
17
cartesianSquare :: [a ] -> [(a , a )]
24
18
cartesianSquare xs = [(x, x') | x <- xs, x' <- xs]
25
19
26
- -- | Finds the nth element of the list (modulo the list's length) .
27
- (!!%) :: [a ] -> Int -> a
28
- xs !!% n = xs !! (n `mod` length xs)
29
-
30
20
data Vec2 a = Vec2 { x :: a , y :: a }
31
21
deriving (Show , Eq , Ord , Functor )
32
22
@@ -63,7 +53,7 @@ step :: Robot -> Robot
63
53
step r = Robot ((r. pos .+. r. vel) .%. boardSize) r. vel
64
54
65
55
stepN :: Int -> Robot -> Robot
66
- stepN n = (!!% n) . period step
56
+ stepN n = (!! n) . iterate step
67
57
68
58
safetyFactor :: [Robot ] -> Int
69
59
safetyFactor rs = foldr1 (*) [length $ filter (\ p -> p. x `xop` center. x && p. y `yop` center. y) ps | (xop, yop) <- cartesianSquare [(<) , (>) ]]
0 commit comments