Allow me to “explain” how quicksort works.
A sequnce of length 1 or less is already sorted.
choose the first value as pivot
result = sorted(less or equal) + the pivot itself + sorted(greater)
I’m essentially just stating the obvious, yet this is an efficient sorting algorithm.
if len(seq) <= 1:
pivot = seq
less = quicksort([value for value in seq[1:] if value < pivot])
more = quicksort([value for value in seq[1:] if value >= pivot])
return less + [pivot] + more
If you describe this as a loop, things get messy.
Another example is navigating a labyrinth:
If got out, done
mark this position as visited
recurse on each choice
un-mark this position
Again, a loop ends up a mess.
Tower of Hanoi?
Moving one ring is easy.
If we know how to move one ring, then it’s easy to move two rings.
If we know how to move two rings, then it’s easy to move three rings.
if we know how to move three rings, then it’s easy to move four rings.
With a loop? Uhh. No.