Best shuffle: Difference between revisions

Content added Content deleted
Line 885: Line 885:
char[] s2 = s1.toCharArray();
char[] s2 = s1.toCharArray();
Collections.shuffle(Arrays.asList(s2));
Collections.shuffle(Arrays.asList(s2));
int i = 0, j = 0;
for (int i = 0; i < s2.length; i++) {
for (int i = 0; i < s2.length; i++) {
if (s2[i] == s1.charAt(i)) continue;
if (s2[i] != s1.charAt(i)) continue;
for (int i = 0; i < s2.length; i++) {
for (int j = 0; j < s2.length; j++) {
if (s2[i] != s2[j] && s2[i] != s1.charAt(j) && s2[j] != s1.charAt(i)) {
if (s2[i] != s2[j] && s2[i] != s1.charAt(j) && s2[j] != s1.charAt(i)) {
char tmp = s2[i];
char tmp = s2[i];
Line 895: Line 894:
break;
break;
}
}
j++;
}
}
i++;
j = 0;
}
}
return s1 + " " + new String(s2) + " (" + count(s1, s2) + ")";
return s1 + " " + new String(s2) + " (" + count(s1, s2) + ")";