Best shuffle: Difference between revisions

m
→‎{{header|AWK}}: Change one paragraph.
m (→‎{{header|AWK}}: Change one paragraph.)
Line 18:
The equivalent programs for [[#Perl 6|Perl 6]] and for [[#Ruby|Ruby]] use several built-in array functions. But if those array functions seem strange to you, and if you can understand this bunch of for loops, then you might prefer this Awk program.
 
This algorithm calculates an order of positions, then fills a new string in this order, by moving each letter from the original string. It will never replace an old letter with an identical letter, unless the remainder of the original string has only this letter. The next position into the order of fillingfill is always the position of the old letter with the most occurrences among the remaining old letters. This special order can always replacechange every old letter, unless some old letter occurs in more than half of the original string.
 
<lang awk># out["string"] = best shuffle of string _s_
Anonymous user