Skip to content

Instantly share code, notes, and snippets.

@JossWhittle
Created August 10, 2012 00:15
Show Gist options
  • Save JossWhittle/3309409 to your computer and use it in GitHub Desktop.
Save JossWhittle/3309409 to your computer and use it in GitHub Desktop.
int[] c = {0,1,2,3,4,5,6,7,8,9};
boolean fin = false;
int count = 1;
while (!fin && count < 1000000) {
int k = 0, j = 0;
for (int i = 0; i < c.length - 1; i++) {
if (c[i] < c[i + 1]) {
k = i;
j = i + 1;
}
}
if (j > 0) {
for (int i = k + 1; i < c.length; i++) {
if (c[k] < c[i]) {
j = i;
}
}
int tmp = c[k];
c[k] = c[j];
c[j] = tmp;
if (k + 1 < c.length - 1) {
int[] d = c.clone();
for (int i = 0; (k + 1) + i < c.length; i++) {
c[(k + 1) + i] = d[(c.length - 1) - i];
}
}
} else {
fin = true;
}
count++;
}
for (int i = 0; i < c.length; i++) {
System.out.print(c[i]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment