@@ -13,20 +13,10 @@ split x (y:ys) | x == y = [] : split x ys
1313 in (y : y') : ys'
1414split _ [] = [[] ]
1515
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-
2216-- | The cartesian product with itself.
2317cartesianSquare :: [a ] -> [(a , a )]
2418cartesianSquare xs = [(x, x') | x <- xs, x' <- xs]
2519
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-
3020data Vec2 a = Vec2 { x :: a , y :: a }
3121 deriving (Show , Eq , Ord , Functor )
3222
@@ -63,7 +53,7 @@ step :: Robot -> Robot
6353step r = Robot ((r. pos .+. r. vel) .%. boardSize) r. vel
6454
6555stepN :: Int -> Robot -> Robot
66- stepN n = (!!% n) . period step
56+ stepN n = (!! n) . iterate step
6757
6858safetyFactor :: [Robot ] -> Int
6959safetyFactor rs = foldr1 (*) [length $ filter (\ p -> p. x `xop` center. x && p. y `yop` center. y) ps | (xop, yop) <- cartesianSquare [(<) , (>) ]]
0 commit comments