trajectory :: Int -> Int -> Accum -> TrajectoryOutcome
trajectory n dim (Accum len cycle nodeArray) 
    = trajectory_ n emptyTrajectory 
  where
    trajectory_ :: Int -> Trajectory -> TrajectoryOutcome
    trajectory_ n (Trajectory trajectory nodes)
        | dim < n            = NoCycle trajectory
        | nodeArray ! n      = NoCycle trajectory
        | Set.member n nodes = Cycle   (n:trajectory)
        | otherwise          = trajectory_ (step n) 
                                           (Trajectory (n:trajectory) 
                                                       (Set.insert n nodes))
trajectory :: Int -> Int -> Accum -> TrajectoryOutcome
trajectory n dim (Accum len cycle nodeArray) 
    = trajectory_ n emptyTrajectory 
  where
    trajectory_ :: Int -> Trajectory -> TrajectoryOutcome
    trajectory_ n (Trajectory trajectory nodes)
        | dim < n            = NoCycle trajectory
        | nodeArray ! n      = NoCycle trajectory
        | Set.member n nodes = Cycle   (n:trajectory)
        | otherwise          = trajectory_ (step n) 
                                           (Trajectory (n:trajectory) 
                                                       (Set.insert n nodes))
trajectory n dim (Accum len cycle nodeArray) 
    = trajectory_ n emptyTrajectory 
  where
    trajectory_ :: Int -> Trajectory -> TrajectoryOutcome
    trajectory_ n (Trajectory trajectory nodes)
        | dim < n            = NoCycle trajectory
        | nodeArray ! n      = NoCycle trajectory
        | Set.member n nodes = Cycle   (n:trajectory)
        | otherwise          = trajectory_ (step n) 
                                           (Trajectory (n:trajectory) 
                                                       (Set.insert n nodes))