Best shuffle: Difference between revisions

Content added Content deleted
(C: incorrect)
(→‎{{header|D}}: account for multibyte strings, which the swap would otherwise interfere with)
Line 100:
=={{header|D}}==
{{works with|D|2}}
<lang d>intiint bestShuffle(chardchar[] s1) {
 
int countSamePositions(chardchar[] r1, chardchar[] r2) {
return count!("a[0] == a[1] && a[1] != b")(zip(r1, r2), '-');
}
 
const len = s1.length;
chardchar[] s2 = s1.dup;
 
if (len < 3) {
Line 131:
} while(countSamePositions(s1, s2) > 0);
char pc = cast(char) problemChar[0];
for (int i; i < len; i++) {
if (s2[i] == '-') {
s2[i] = pcproblemChar[0];
}
}