Pascal's triangle is generated by starting with
1 and having each row formed from successive additions. Here, instead, we're going to form a triangle by alternating multiplication and addition.
We start row
1 with just a solitary
1. Thereafter, addition is done on the odd rows, and multiplication is done on the even rows (1-indexed). When performing the addition step, assume the spaces outside of the triangle are filled with
0s. When performing the multiplication step, assume that the outside is filled with
Here's the full triangle down to 7 rows. The
+ on the left shows what step was performed to generate that row.
1 1 2 * 1 1 3 + 1 2 1 4 * 1 2 2 1 5 + 1 3 4 3 1 6 * 1 3 12 12 3 1 7 + 1 4 15 24 15 4 1
n, output the
nth row of this triangle.
- You may choose to 0-index instead, but then please realize that the addition and multiplication rows must flip-flop, so that the exact same triangle is generated as above. Please state in your submission if you choose to do this.
- The input and output can be assumed to fit in your language's native integer type.
- The input and output can be given in any convenient format.
- Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
- If possible, please include a link to an online testing environment so other people can try out your code!
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
Showing two possible examples of output out of many: a list, or a space separated string.
4 [1, 2, 2, 1] 8 "1 4 60 360 360 60 4 1"