Cycle detection: Difference between revisions

m
(→‎Functional Python: Refactoring cycleLength in terms of until, then reimplementing until as iterative)
Line 1,573:
But recursion scales poorly in Python, and the version above, while good for lists of a few hundred elements, will need refactoring for longer lists and better use of space.
 
If we start by refactoring the recursion into the form of a higher order (but still recursive) '''until( p)( f)( x)''' function, we can then reimplement the internals of ''until'' itself to avoid recursion, without losing the benefits of compositional structure:
 
Recursive ''until'':
9,655

edits