Anonymous user
Best shuffle: Difference between revisions
Removed division by zero bug from first D version
(Removed division by zero bug from C version) |
(Removed division by zero bug from first D version) |
||
Line 306:
enum int MAX_VLA_SIZE = 1024;
const int len = txt.length;
if (len == 0)
return;
// txt and result must have the same length
Line 322 ⟶ 324:
fmax = counts[c];
}
assert(fmax > 0 && fmax <= len);
// how long can our cyclic groups be?
Line 372 ⟶ 375:
void main() {
auto data = ["abracadabra", "seesaw", "elk", "grrrrrr",
"
foreach (txt; data) {
auto shuf = txt.dup;
Line 388 ⟶ 391:
up, pu, (0)
a, a, (1)
aabbbbaa, bbaaaabb, (0)
, , (0)
xxxxx, xxxxx, (5)</pre>
Using idea from [http://rosettacode.org/wiki/Talk:Best_shuffle#J_implementation_notes J implementation notes] at discussion page.
{{works with|D|2.051}}
|