Recursive definition of divisibility java

public class divisorplot {
public static void main(String args[]) {
int x = 12;
int triangle[][] = new int[x][x];
for (int i = 0; i < x; i++) {
for (int j = 0; j < x; j++) {
triangle[i][j] = 0;
}
}
for(int i = 0; i < x; i++) {
triangle[i][0] = 1 ;
}
for (int i = 1; i < x; i++) {
for (int j = 1; j <=i; j++) {
int sum = 0;
for (int k = 1; k <= j; k++) {
// recursive definition of divisibility, triangle A051731 in the OEIS.
sum = sum + (triangle[i-k][j-1]) - (triangle[i-k][j]);
}
triangle[i][j] = sum;
}
}
for (int i = 0; i < x; i++) {
for(int j=0;j<x;j++) {System.out.print(triangle[i][j]+ " ");
}
System.out.println();
}
}
}
//Mats Granvik, email mats.granvik(at)abo.fi
Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.