[Question]
  [
[Pascal's triangle](https://en.wikipedia.org/wiki/Pascal%27s_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 `0`s. When performing the multiplication step, assume that the outside is filled with `1`s.
Here's the full triangle down to 7 rows. The `*` or `+` 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
```
## Challenge
Given input `n`, output the `n`th row of this triangle.
## Rules
* 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](http://meta.codegolf.stackexchange.com/q/2447/42963).
* 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](http://meta.codegolf.stackexchange.com/q/1061/42963) are forbidden.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so all usual golfing rules apply, and the shortest code (in bytes) wins.
## Examples
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"
```
  
[Answer]
# [Pascal](https://www.freepascal.org/), ~~249~~ ~~247~~ 233 bytes
*Well, this is **Pascal's** alternating triangle.*
*1 byte saved thanks to @Mr.Xcoder*
```
function f(n,k:integer):integer;begin if((k<1)or(k>n)or(n=1))then f:=n mod 2 else if n mod 2=0then f:=f(n-1,k-1)*f(n-1,k)else f:=f(n-1,k-1)+f(n-1,k)end;
procedure g(n:integer);var k:integer;begin for k:=1to n do write(f(n,k),' ')end;
```
[Try it online!](https://tio.run/##XY/NUsMgFIX3eYqzK2jiiCsniO8SE0AkvWQobR8/3tCmM7qBc3/Ox2EZTuMwd24Z1yUnn4cjltrSqzvTWEIiOEFt7AMV622Wu9Bf1gdCcELEDyVTFvGTtouMkrJ8Wzb2hnBME95g55PlXdxr87ovMLxTbeyUfLpLWXf/jJ4fI5p0w0FHO52zhRf0yKUvQ0b8l86lrWdUSfzylHDNoVhRPyTbAw4VuLKzAUKLnx67v6kAbm@IgN5AgSnvG@XG9iJIfSPOJFjWcHy8rL8)
[Answer]
# [Python 2](https://docs.python.org/2/), ~~97~~ ~~93~~ ~~86~~ ~~81~~ 78 bytes
*-4 bytes thanks to Rod. -10 bytes thanks to Halvard Hummel.*
```
f=lambda n:n and[[i+j,i*j][n%2]for i,j in zip([n%2]+f(n-1),f(n-1)+[n%2])]or[1]
```
0-indexed.
[Try it online!](https://tio.run/##JYtBCsMgFAX3OcXbFLTaRdJFIZCTfFwYUumX9ivGTXp5S@xqYIbJR30lmVoLy9t/1s1DZoGXjYhNtHyNjuQyuZAK2Eaw4MtZdWeCktuo7R@mO@1SodG1@tzrjgV0t3i4Yej/efcwIxeWiqBYtx8 "Python 2 – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~17~~ 12 bytes
```
µ×+LḂ$?Ḋ1;µ¡
```
This is a full program (or niladic link) that takes input from STDIN.
[Try it online!](https://tio.run/##AR4A4f9qZWxsef//wrXDlytM4biCJD/huIoxO8K1wqH//zc "Jelly – Try It Online")
### How it works
```
µ×+LḂ$?Ḋ1;µ¡  Main link. No arguments. Implicit argument: 0
          µ¡  Start a monadic chain and apply the ntimes quick to the previous one.
              This reads an integer n from STDIN and executes the previous chain n
              times, with initial argument 0, returning the last result.
µ             Start a monadic chain. Argument: A (array or 0)
       Ḋ          Dequeue; yield A without its first element.
   LḂ$?           If the length of A is odd:
 ×                    Multiply A and dequeued A.
                  Else:
  +                   Add A and dequeued A.
        1;        Prepend a 1 to the result.
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~96 89~~ 87 bytes
* 2 bytes Thanks to Mr. Xcoder: `s=[1]`
* A bit different than [totallyhuman's answer](https://codegolf.stackexchange.com/a/138230/59523)
```
s=a=[1]
for i in range(1,input()):a=s+[[k+l,k*l][i%2]for k,l in zip(a[1:],a)]+s
print a
```
[Try it online!](https://tio.run/##Fco7DoAgDADQ3VOwmICw4GJiwkmaDh38NJBKAAe9PMY3v/y085K59xoogMdhv4pixaIKybFp71jy3bQxK4VqAaJNLk4JgccZ/xxd@vvLWRP4FR0ZtHXIhaUp6n35AA "Python 2 – Try It Online")
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 25 bytes
```
{1a\{2%!_2$+\{.*}{.+}?}/}
```
0-indexed.
[Try it online!](https://tio.run/##S85KzP1fWPe/2jAxptpIVTHeSEU7plpPq7ZaT7vWvla/9n9dwX8zAA "CJam – Try It Online")
### Explanation
This is an anonymous block that takes the number from the stack and leaves the result on the stack.
```
1a                        Push [1].
  \                       Bring the number to the top.
   {                 }/   For reach number 0 .. arg-1, do:
    2%!                    Push 0 if even, 1 if odd.
       _                   Copy that.
        2$+                Copy the list so far and prepend the 0 or 1 to it.
           \               Bring the 0 or 1 back to the top.
            {.*}{.+}?      If 1, element-wise multiplication. If 0, element-wise addition.
```
[Answer]
# Mathematica, 92 bytes
```
(s={i=1};While[i<#,s=Flatten@{1,{Tr/@#,Times@@@#}[[i~Mod~2+1]]&@Partition[s,2,1],1};i++];s)&
```
[Try it online!](https://tio.run/##DcyxCsMgEADQXykIocWDYqZCKtyUrZAh0EEcpDXkwCjkbpPk123fB7wtyEofbottV7aVrDmG90opOnoqYDumIBIzVgN1LhLSHRXMtEVGRHU4R@erfM9eG@87nMIuJFSyY@jBePhvpLUf@Na1aacsF1zcw7cf "Mathics – Try It Online") (in order to work on mathics "Tr" is replaced with "Total")
[Answer]
# [Haskell](https://www.haskell.org/), ~~76~~ 72 bytes
0-indexed solution:
```
(p!!)
p=[1]:[zipWith o(e:l)l++[1]|(l,(o,e))<-zip p$cycle[((*),1),((+),0)]]
```
[Try it online!](https://tio.run/##DcmxDoIwEIDh3ac4Eoc7KUYmE9JOvACbJsjQ4AENZ2mgi8ZntzL8y/dPdptZJA3mkTBkGR2Cacuuaj8u3FycYEGuhCTPd/2iKFwUE@li/xCO/bsXbhFPpEpSiDmpC3VdelnnwUBYnY9whmFvZfsEozWMHOvFR/ZxS9dfP4gdt1Tc66b5Aw "Haskell – Try It Online")
### Explanation
`p` recursively defines the alternating triangle, the base case/first element of it is `[1]`
```
p=[1]:[                                                            ]
```
It then builds the triangle by taking the previous line (`l`). To know what to do with it we need to keep track of the correct operator (`o`) and the corresponding neutral element (`e`):
```
                           |(l,(o,e))<-zip p$cycle[((*),1),((+),0)]
```
From this build the new line by duplicating the line and for one copy we prepend the neutral element, zip them with the operator and append a 1:
```
       zipWith o(e:l)l++[1]
```
[Answer]
# [R](https://www.r-project.org/), ~~108~~ 98 bytes
*-10 bytes by replacing the actual multiply sign with a plus sign. Please forgive me.*
```
f=function(n){if(n<3)return(rep(1,n))else{v=f(n-1)};if(n%%2)`*`=`+`;return(c(1,v[3:n-2]*v[-1],1))}
```
[Try it online!](https://tio.run/##LcpNCoMwEEDhvfcQZqxZTNI/anMSEQKSAaFMS6rZiGePDrj5Nu@lUtjzIuM8fQUE14lB3g5TnJckkOIPqBXE@PnHNfsjGsKt06uuLYYm@HAJ3bmPx5x79xJjhyb3hoaWELfCQFgxWMUpV@Wm3JWH8sSq7A "R – Try It Online")
Quite pleased with the general method (first time I've aliased a primitive) but I'm sure there's golfing to be done on it yet, especially with the awkward handling of cases where n<3 which leads to a lot of boilerplate.
[Answer]
## [Husk](https://github.com/barbuz/Husk), ~~17~~ 16 bytes
```
!G₅;1¢e*+
:1Sż⁰t
```
[Try it online!](https://tio.run/##ASgA1/9odXNr/yBt4oKB4bijMTD/IUfigoU7McKiZSorCjoxU8W84oGwdP// "Husk – Try It Online")
A 1-indexed solution.
## Explanation
The first line is the main function, which calls the helper function on the second line.
The helper function is usually called with `₁`, but in this case I'm using the *overflowing labels* feature of Husk: if you refer to a line **N** in a program with **M < N** lines, you get line **N mod M** with modifier function **M / N** applied to it.
The second modifier function is `flip`, so I'm using `₅` to flip the arguments of the helper function with no additional byte cost.
Here is the helper function.
```
:1Sż⁰t  Takes a function f and a list x.
   ż    Zip preserving elements of longer list
    ⁰   using function f
  S  t  x and its tail,
:1      then prepend 1.
```
Here is the main function.
```
!G₅;1¢e*+  Takes a number n.
      e*+  2-element list of the functions * and +
     ¢     repeated infinitely.
 G         Left scan this list
  ₅        using the flipped helper function
   ;1      with initial value [1].
!          Get n'th element.
```
[Answer]
# [Python 2](https://docs.python.org/2/), 83 bytes
Give some love to `exec`  
0-indexed
```
l=[1];exec"l[1:]=[[a+b,a*b][len(l)%2]for a,b in zip(l,l[1:])]+[1];"*input()
print l
```
[Try it online!](https://tio.run/##HctBCoAgEADAe6@QIND0opeg6CXLHjSMhGWTMKg@b9R9Jt9l29nVSjNYnOIVl5bAjjgDeB2M7wMCRZakOofrfghvgkgsnpQlmZ8q1N9t@8T5LFI1@UhcBNU6vA)
[Answer]
# [Pyth](https://pyth.herokuapp.com), 22 bytes
Saved tons of byte thanks to [@FryAmTheEggman](https://codegolf.stackexchange.com/users/31625/fryamtheeggman)! The initial solution is below.
```
u++1@,+VGtG*VGtGlG1Q[1
```
**[Full Test Suite (0-indexed).](https://pyth.herokuapp.com/?code=u%2B%2B1%40%2C%2BVGtG%2aVGtGlG1Q%5B1&input=7&test_suite=1&test_suite_input=0%0A1%0A2%0A3%0A4%0A5%0A6%0A7&debug=0)**
# [Pyth](https://pyth.readathedocs.io), ~~40 38 36~~ 35 bytes
This feels ~~waaaaaaaay too~~ reasonably long. Suggestions are welcome.
```
K]1VStQ=K++]1m@,sd*hded%N2C,KtK]1;K
```
**[Test Suite](https://pyth.herokuapp.com/?code=K%5D1VStQ%3DK%2B%2B%5D1m%40%2Csd%2ahded%25N2C%2CKtK%5D1%3BK&input=5&test_suite=1&test_suite_input=1%0A%0A2%0A%0A3%0A%0A4%0A%0A5%0A%0A6%0A%0A7%0A&debug=0&input_size=2)** or **[Try it online!](http://pyth.herokuapp.com/?code=K%5D1VStQ%3DK%2B%2B%5D1m%40%2Csd%2ahded%25N2C%2CKtK%5D1%3BK&input=5&test_suite_input=1%0A%0A2%0A%0A3%0A%0A4%0A%0A5%0A%0A6%0A%0A7%0A&debug=0&input_size=2)**
[Answer]
# [J](http://jsoftware.com/), 32 bytes
```
[:(1,]{::(}.@,-.)(*;+)[)~/2|]-i.
```
[Try it online!](https://tio.run/##y/r/P03B1koh2krDUCe22spKo1bPQUdXT1NDy1pbM1qzTt@oJlY3U4@LKzU5I19BycohTclAwc5KIVNPwfz/fwA "J – Try It Online")
[Answer]
# [Perl 5](https://www.perl.org/), 111 + 2 (-na) = 113 bytes
```
sub t{($r,$c)=@_;!--$r||!$c||$c>=$r?1:eval"t($r,$c)".($r%2?"*":"+")."t($r,$c-1)"}say map{t($F[0],$_).$"}0..$_-1
```
[Try it online!](https://tio.run/##NYpBCsIwEAC/0i4rGO2GRChIpdaTN18gEmLooVDbkERBmn7d2IPehpmxrevLlPzznoVpja5Aw@qTOuRE6GLM0cSI5lija2TVvnQP4XcBX2C1a2ADFWyB8X8hyWD2@p09tJ0Wd76KW4GKcYRZcI6KZEr7z2hDNw4@0aXkQopEg/4C "Perl 5 – Try It Online")
[Answer]
# Mathematica, 70 bytes
```
Fold[#2@@@Partition[#,2,1,{-1,1},{}]&,{1},PadRight[{},#,{1##&,Plus}]]&
```
Try it at the [Wolfram sandbox](https://sandbox.open.wolframcloud.com/)! It doesn't work in Mathics, unfortunately. It's 0-indexed.
Explanation: `Partition[#,2,1,{-1,1},{}]` takes a list and returns all the two-element sublists, plus 1-element lists for the start and end — e.g., `{1,2,3,4}` becomes `{{1}, {1,2}, {2,3}, {3,4}, {4}}`. `PadRight[{},#,{1##&,Plus}]` makes an alternating list of `1##&` (effectively `Times`) and `Plus`, whose length is the input number. Then `Fold` repeatedly applies the partition function with the `Plus`es and `Times`es applied to it, to make the rows of the triangle.
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), ~~143~~ ~~134~~ 128 bytes
*-4 bytes thanks to [Phaeze](https://codegolf.stackexchange.com/users/19547/phaeze)*  
*-5 bytes thanks to [Zac Faragher](https://codegolf.stackexchange.com/users/56606/zac-faragher)*  
```
n=>{int[]b={1},c;for(int i=0,j;++i<n;b=c)for(c=new int[i+1],c[0]=c[i]=1,j=0;++j<i;)c[j]=i%2<1?b[j-1]+b[j]:b[j-1]*b[j];return b;}
```
[Try it online!](https://tio.run/##ZVBdS8MwFH3Pr7gOhMZ2ZZ3fppmIuKcJooIPpQ9tlrlbunQmqVNGf3vth0yK5yE5Offcj1xhxqLQsi4Nqnd4@TZWbvwFqg9GiEo20mwTIX91sifQQOSJMXDX8V5pYWxiUcBngUt4TFA59BD6M7WYl0qEqKwHzRHFM1gBrxWf7btnyvdB5Qm2KrTTCIB84mXMdTFULOWCtrrgSu66bHSD2BPRJOYiwpgHXsYnjTkLkVERZTHH42kY3KZRNg5it7nim56ftJxpaUutIGVVzQYzGqvbdaDalnYY2a0xl@A4XQg43BfKFLn0n2WybNYmHUrhiIMq85wOEodLaLFqP@g/JdrIvhyl/muxQGMd6s8L/ZCItfMFfHZo8qbRykZyYQQjStm/kgNjP87QVJEhq0hVB2RKTskZOScX5JJckWsSTH4A "C# (.NET Core) – Try It Online")
Explanation:
```
n =>
{
    int[] b = { 1 }, c;               // Create first layer
    for(int i = 0, j; ++i < n; b = c) // Iterate for every layer, replace last layer with a new one
        for(c = new int[i+1],         // Create new layer
            c[0] = c[i] = 1,          // First and last elements are always 1
            j = 0;
            ++j < i; )                // Replace every element (besides 1st and last)...
                c[j] = i % 2 == 0 ?
                    b[j - 1] + b[j] : // ... with addition...
                    b[j - 1] * b[j];  // ... or multiplication of two from previous layers
    return b;                         // Return latest layer
};
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~83~~ 82 bytes
```
->n{a=[1];p=0;n.times{a=[p=1-p,*a,p].each_cons(2).map{|x|x.reduce([:+,:*][p])}};a}
```
[Try it online!](https://tio.run/##HcvRCoMgFADQ977CR2110T0m9iMiw6kxoexSCxrptzu21wNnO56fOqnaj@mySgsjUXGZ4B2XsP8Eleixa22HBoJ1r4db007vDBaLVz7zCVvwhwtUD7duaI1Gw0qRtlTKAQRn/0X8SnLMDSFIJnB2nklsQvL1Cw "Ruby – Try It Online")
This is 0-indexed.
[Answer]
# [Racket](https://racket-lang.org/), 116 bytes
```
(define(t n[i 1][r'(1)])(if(= n 1)r(t(- n 1)(- 1 i)(cons 1(append(map(if(> i 0)* +)(cdr r)(reverse(cdr r)))'(1))))))
```
[Try it online!](https://tio.run/##Lc3NDsIwCADgu09B4kHQmIi/J32RZYdmZaZRsWGNr187lMMHBAIWhoeUunwGvYP9GowyJhUsoF0C7jtbIVNPmEa8ggKTYcGtVy0xJMLhrRMwhpxFI75CnpdvkGBHa9i0eTQwQpOP2CT/lmg@7FHbN6ZFc@8e3KN7cs/uheoX "Racket – Try It Online")
[Answer]
# TI-Basic (TI-84 Plus CE), 100 bytes
```
Prompt X
{1→M
For(A,2,X
LM→L
A→dim(M
For(B,2,A–1
If A/2=int(A/2
Then
LL(B–1)LL(B→LM(B
Else
LL(B–1)+LL(B→LM(B
End
End
1→LM(dim(LM
End
LM
```
1-indexed, prompts user for input and prints a list containing the `n`th row of Pascal's Alternating Triangle.
While looping: LM is the current row, and LL is the previous row.
TI-Basic is a [tokenized language](http://tibasicdev.wikidot.com/one-byte-tokens). All tokens used here are one-byte tokens.
I think I can golf this further by modifying M in-place from the end.
Explanation:
```
Prompt X            # 3 bytes; get user input, store in X
{1→M                # 5 bytes, store the first row into LM
For(A,2,X           # 7 bytes, Loop X-1 times, with A as the counter, starting at 2
LM→L                # 5 bytes, copy list M into list L
A→dim(M             # 5 bytes, extend M by one
For(B,2,A–1         # 9 bytes, for each index B that isn't the first or last...
If A/2=int(A/2      # 10 bytes,    if A is even...
Then                # 2 bytes,     then...
LL(B–1)LL(B→LM(B     # 17 bytes,        the Bth item in this row is the Bth times the (B-1)th of the previous row
Else                # 2 bytes,     else...
LL(B–1)+LL(B→LM(B    # 18 bytes,        the Bth item in this row is the Bth plus the (B-1)th of the previous row
End                 # 2 bytes,     endif
End                 # 2 bytes,  endfor
1→LM(dim(LM         # 9 bytes, the last item is always 1
End                 # 2 bytes, endfor
LM                  # 2 bytes, Implicitly print the final row
```
[Answer]
# JavaScript (ES6), ~~71~~ ~~69~~ 66 bytes
```
f=n=>n?(p=f(n-1),[...p.map((v,i)=>i--?n%2?v*p[i]:v+p[i]:1),1]):[1]
```
[Try it online!](https://tio.run/##HcoxDsIgFADQvaf4i8lHChHHVspBCAOpxXxTgVDDYjw7Eqe3vKev/lgL5beI6b61FnTUSzSYdcAoFButlDLLl8@IdSSmFxLCxNPV1HO25KbK//SpHJusci2kAlh9AQINl7lzA9XlnBh8BoA1xSPtm9zTAwMSY/PwbT8 "JavaScript (Node.js) – Try It Online")
0-indexed.  
**-3 bytes** by @Arnauld
```
f=n=>n?(p=f(n-1),[...p.map((v,i)=>i--?n%2?v*p[i]:v+p[i]:1),1]):[1]
for (var i = 0; i < 10; ++i) {
  console.log(JSON.stringify(f(i)));
}
```
]