Best shuffle: Difference between revisions

m
(C: document algorithm)
Line 9:
This approach is totally deterministic, and is based on the final J implementation from the talk page.
 
In essence: we form cyclic groups of character indices where each cyclic group is guaranteed to represent each character only once (two instances of the letter a must have their indices in separate groups), and then we rotate each of the cyclic groups. We then use the before/after version of these cycles to shuffle the original text. The only way a character can be repeated, here, is when a cyclic group contains only one character index, and this can only happen when more than half of the text uses that character.
 
<lang C>#include<assert.h>
6,962

edits