Challenge
Given a sequence of non-negative integers, create a function that output a descendant pyramid where the children are the sum of both parent numbers.
The result is outputted as an string using tab \t
.
Note: trailing tabs on each line are not required
1\t\t2\t\t3\n\t3\t\t5\t\n\t\t8\t\t results in
1 2 3
3 5
8
Optionally result can be outputted as an array using an empty position as space.
[[1,,2,,3],
[,3,,5,],
[,,8,,]]
Example:
Given 4,5,7,3,4,2
Output:
4 5 7 3 4 2
9 12 10 7 6
21 22 17 13
43 39 30
82 69
151
Rules
- Standard code-golf rules apply
- Input can be a string using any separator or an array
- Leading/trailing newlines and tabs are permitted (but not required as long as the output is an inverted pyramid)
Test Cases
Input: 1,3,5
1 3 5
4 8
12
Input: 9,8,7,6,5
9 8 7 6 5
17 15 13 11
32 28 24
60 52
112
Input: 5,5,2,5
[[5,,5,,2,,5],
[,10,,7,,7,],
[,,17,,14,,],
[,,,31,,,]]
Input: 3,3,3
[[3,,3,,3],
[,6,,6,],
[,,12,,]]
Winning criteria is code-golf
Note: This challenge is very close to Generate Pascal's triangle. The difference is the custom starting sequence (pascal goes from 1 and in ascendant mode, this from an input and in descendant mode).
non-negative integers
do we have to handle0
? There are some golfing possibilities if empty spaces are filled with0
s. \$\endgroup\$