Best shuffle: Difference between revisions
Content added Content deleted
m (→{{header|Icon}} and {{header|Unicon}}: comments) |
m (→{{header|Icon}} and {{header|Unicon}}: tweak comments) |
||
Line 419: | Line 419: | ||
=={{header|Icon}} and {{header|Unicon}}== |
=={{header|Icon}} and {{header|Unicon}}== |
||
The approach taken will run in O(n*(n-1)/2) time and swap once per changed character. The algorithm is conceptually simpler |
The approach taken will run in O(n*(n-1)/2) time and swap once per changed character. The algorithm is concise and conceptually simpler avoiding the lists of indices, sorting, cycles, groups, and special cases requiring rotation. Additionally, this can be trivially modified to randomize the shuffle. |
||
<lang icon>procedure main(args) |
<lang icon>procedure main(args) |
||
while scram := bestShuffle(line := read()) do |
while scram := bestShuffle(line := read()) do |