I'm looking to generate an M-Arithmetic triangle of order 4. It's described here: http://www.sciencedirect.com/science/article/pii/S0024379509003577?np=y
And it looks like this:
1
1 1 1 1
1 2 3 4 3 2 1
1 3 6 10 12 12 10 6 3 1
1 4 10 20 31 40 44 40 31 20 10 4 1
And so on. The first two rows are always constant in my M-arithmetic triangle of order 4. From then on, each term is the sum of the term above it and the 3 terms on the left of the term above it.
The variables to define the size of the matrix which will contain these numbers are as follows
int y = user.nextInt();
int max = 3*y + 1;
int[][] m-arith = new int [y][max];
How do I generate the M-arithmetic triangle in code? As well as put zeroes into all the places not filled by numbers? I could declare the matrix manually like this (just gonna show a few rows):
int[][] m-arith = {
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{1,2,3,4,3,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
};
But this seems like a monumental waste of time if I need anything more than a few rows.
Any ideas?
edit: For that matter, the code to generate an M-arithmetic triangle of any order would be interesting. However, am looking for solution specific to the order 4 triangle.