Visualize a Difference Pyramid 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.
Jelly, 16 bytes

IA$ṖÐ¿UṚz”@ṚGḟ”@


Try it online!

Background

Generating the differences is quite straightforward. For input

[1, 2, 3, 4, 5, 6, 7, 8, 9]


IA$ṖÐ¿ (absolute value of increments while there is more than one element) yields the following ragged 2D array.

[1, 2, 3, 4, 5, 6, 7, 8, 9]
[1, 1, 1, 1, 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, 0]
[0, 0]
[0]


U reverses the order of the columns and Ṛ the order of the rows, yielding the following.

[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, 0]
[1, 1, 1, 1, 1, 1, 1, 1]
[9, 8, 7, 6, 5, 4, 3, 2, 1]


Now, we transpose rows and columns with z”@, which pads all rows to the same length before transposing. The result is the following.

[0, 0, 0, 0, 0, 0, 0, 1, 9]
[@, 0, 0, 0, 0, 0, 0, 1, 8]
[@, @, 0, 0, 0, 0, 0, 1, 7]
[@, @, @, 0, 0, 0, 0, 1, 6]
[@, @, @, @, 0, 0, 0, 1, 5]
[@, @, @, @, @, 0, 0, 1, 4]
[@, @, @, @, @, @, 0, 1, 3]
[@, @, @, @, @, @, @, 1, 2]
[@, @, @, @, @, @, @, @, 1]


Reversing the rows gives

[@, @, @, @, @, @, @, @, 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]


To turn the 2D array into a whitespace-separated string, we use the built-in grid atom (G). It joins columns by spaces and rows by linefeeds, yielding the following result.

@ @ @ @ @ @ @ @ 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


All that's left to do is removing the padding character with ḟ”@, yielding

        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


which is the desired output.