Best shuffle: Difference between revisions

m
m (→‎{{header|Icon}} and {{header|Unicon}}: fix order + description)
Line 419:
 
=={{header|Icon}} and {{header|Unicon}}==
The approach taken requires 2n memory and will run in O(n*(n-1)/^2) time and swapswapping once per final changed character. The algorithm is concise and conceptually simpler avoiding the lists of indices, sorting, cycles, groups, and special cases requiring rotation. Additionally,It thisproceeds canthrough bethe triviallyentire modifiedstring toswapping randomizecharacters ensuring that neither of the shuffletwo characters are swapped with another instance of themselves in the ''original'' string.
 
Additionally, this can be trivially modified to randomize the shuffle.
<lang icon>procedure main(args)
while scram := bestShuffle(line := read()) do
Anonymous user