Permutations by swapping: Difference between revisions

m
Line 1,647:
end
end
println("There were $iters iterations, and this is the same as $(high-low+1) factorial, or $(factorial(high-low+1)).")
end
johnsontrotter(1,4)
</lang>
Recursive (note this uses memory of roughtly (n+1)! bytes, where n is the number of elements, in order to store the accumulated permutations in a list, and so the above, iterative solution is to be preferred for larger numbers of elements over 9 or so):
<lang julia>
function johnsontrotter(low, high)
4,102

edits