Skip to content

Instantly share code, notes, and snippets.

@Dark32
Created January 22, 2016 06:56
Show Gist options
  • Save Dark32/a82db3451e1a1d1f5262 to your computer and use it in GitHub Desktop.
Save Dark32/a82db3451e1a1d1f5262 to your computer and use it in GitHub Desktop.
/**
* Created by andrew on 22.01.16.
*/
public class Main {
public static void main(String []args){
int n = 8;
int k = 2;
int r[][] = new int[k][n/k];
int s = sum(n);
if (s%k != 0 ) {
System.out.println(0);
return;
}
int jm = n/(2*k);
int im = k;
int d = 1;
for(int i = 0; i < im;i++){
for (int j = 0; j <jm; j++){
int min = d;
int max = n - d+1;
d++;
r[i][j] = min;
r[i][n/k-j-1] = max;
}
}
for(int i = 0; i <k;i++){
for (int j = 0; j <n/k; j++){
System.out.print(r[i][j]+" ");
}
System.out.println();
}
}
private static int sum(int s){
return (s+1)*s/2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment