A difference pyramid is a pyramid where each new diagonal is the absolute value of the differences between the elements of the last diagonal. For example, if we start with the array
2 5 4 9 3 4
Now, we arrange these in a diagonal column:
2
5
4
9
3
4
Now, we fill in the next diagonal. The absolute differences between the consecutive elements of this array are:
3 1 5 6 1
So that is our next diagonal.
2
3 5
1 4
5 9
6 3
1 4
Repeat until the pyramid is filled in:
2
3 5
2 1 4
2 4 5 9
1 3 1 6 3
0 1 4 5 1 4
The Challenge
Given a list of positive integers in the range [0, 9]
, generate this ASCII-art representation of the difference pyramid for that particular array. The input is guaranteed to contain at least two elements. You may take these numbers in any reasonable format. (Array/list/whatever you call it, a string, command line arguments, etc.) Trailing spaces on each line and up to one trailing newline are allowed.
Test IO
[1, 2, 3, 4, 5, 6, 7, 8, 9]
1
1 2
0 1 3
0 0 1 4
0 0 0 1 5
0 0 0 0 1 6
0 0 0 0 0 1 7
0 0 0 0 0 0 1 8
0 0 0 0 0 0 0 1 9
[4, 7]
4
3 7
[3, 3, 3]
3
0 3
0 0 3
[1, 3, 6, 3, 4, 9]
1
2 3
1 3 6
1 0 3 3
1 2 2 1 4
1 0 2 4 5 9
[8, 7, 3, 2, 4, 5, 9, 1, 6]
8
1 7
3 4 3
0 3 1 2
2 2 1 2 4
0 2 0 1 1 5
0 0 2 2 3 4 9
1 1 1 1 1 4 8 1
0 1 0 1 0 1 3 5 6
As usual, this is code-golf, so standard loopholes apply, and shortest answer in bytes wins!
Inspired by this OEIS and this conjecture.