run dim = nodes_ $ foldl' iter (emptyAccum dim) [1..dim]
  where
    iter :: Accum -> Int -> Accum
    iter acc@(Accum len cycle isNodeVisited) n =
        let 
            trajectoryOutcome = trajectory n dim acc
        in 
            case trajectoryOutcome of
                NoCycle nodes -> 
                    acc {isNodesVisited_ = isNodeVisited // [(i,True) | i <- nodes]}
                
                Cycle nodes -> 
                    let cycle' = getCycle nodes
                        len' = length cycle'
                        isNodeVisited' = (isNodesVisited_ acc) // [(i,True) | i <- nodes]
                    in 
                        if len < len' then Accum len' cycle' isNodeVisited'
                                      else acc {isNodesVisited_ = isNodeVisited'}
run dim = nodes_ $ foldl' iter (emptyAccum dim) [1..dim]
  where
    iter :: Accum -> Int -> Accum
    iter acc@(Accum len cycle isNodeVisited) n =
        let 
            trajectoryOutcome = trajectory n dim acc
        in 
            case trajectoryOutcome of
                NoCycle nodes -> 
                    acc {isNodesVisited_ = isNodeVisited // [(i,True) | i <- nodes]}
                
                Cycle nodes -> 
                    let cycle' = getCycle nodes
                        len' = length cycle'
                        isNodeVisited' = (isNodesVisited_ acc) // [(i,True) | i <- nodes]
                    in 
                        if len < len' then Accum len' cycle' isNodeVisited'
                                      else acc {isNodesVisited_ = isNodeVisited'}
run dim = nodes_ $ foldl' iter (emptyAccum dim) [1..dim]
  where
    iter :: Accum -> Int -> Accum
    iter acc@(Accum len cycle isNodeVisited) n =
        let 
            trajectoryOutcome = trajectory n dim acc
        in 
            case trajectoryOutcome of
                NoCycle nodes -> 
                    acc {isNodesVisited_ = isNodeVisited // [(i,True) | i <- nodes]}
                
                Cycle nodes -> 
                    let cycle' = getCycle nodes
                        len' = length cycle'
                        isNodeVisited' = (isNodesVisited_ acc) // [(i,True) | i <- nodes]
                    in 
                        if len < len' then Accum len' cycle' isNodeVisited'
                                      else acc {isNodesVisited_ = isNodeVisited'}