Write a function
private int index(int i, int length)
which computes the right index for the loop variable i
EDIT
Wasn't that easy as i first thought:
public static void main(String[] args) {
int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
for (int i = 0; i < array.length; i++) {
System.out.println(array[index(i, array.length)]);
}
}
private static int index(int i, int length) {
int third = (length + 2) / 3;
if (length % 3 == 1 && i >= third) { // spezial, because second third is smaller
return index(i - 1, length - 1);
}
int group = i % third;
return (group) * 3 + (i / third);
}
EDIT
did some cleanup;