[Question]
  [
The pyramid begins with the row `1 1`. We'll call this row 1. For each subsequent row, start with the previous row and insert the current row number between every adjacent pair of numbers that sums to the current row number.
$$
1\quad1\\
1\quad\color{red}{2}\quad1\\
1\quad\color{red}{3}\quad2\quad\color{red}{3}\quad1\\
1\quad\color{red}{4}\quad3\quad2\quad3\quad\color{red}{4}\quad1\\
1\quad\color{red}{5}\quad4\quad3\quad\color{red}{5}\quad2\quad\color{red}{5}\quad3\quad4\quad\color{red}{5}\quad1\\
1\quad\color{red}{6}\quad5\quad4\quad3\quad5\quad2\quad5\quad3\quad4\quad5\quad\color{red}{6}\quad1\\
\cdots
$$
This pyramid is an example of a false pattern. It seems to encode the prime numbers in the lengths of its rows, but the pattern breaks down later on. You may wish to learn more about this sequence from a recent [Numberphile video](https://www.youtube.com/watch?v=NsjsLwYRW8o) which is the inspiration for this question.
## Task
Output the sequence. You may do so in any of the following ways:
| Method | Example input | Example output |
| --- | --- | --- |
| The infinite sequence as rows. We must be able to tell the rows apart somehow. | - | 1 11 2 11 3 2 3 11 4 3 2 3 4 1... |
| The infinite sequence as numbers, top to bottom, left to right. | - | 1 1 1 2 1 1 3... |
| The first \$n\$ rows of the pyramid, 1-indexed. We must be able to tell the rows apart somehow. | 3 | 1 11 2 11 3 2 3 1 |
| The first \$n\$ rows of the pyramid, 0-indexed. We must be able to tell the rows apart somehow. | 3 | 1 11 2 11 3 2 3 11 4 3 2 3 4 1 |
| The first \$n\$ numbers in the pyramid, 1-indexed. | 4 | 1 1 1 2 |
| The first \$n\$ numbers in the pyramid, 0-indexed. | 4 | 1 1 1 2 1 |
| The \$n\$th row in the pyramid, 1-indexed. | 2 | 1 2 1 |
| The \$n\$th row in the pyramid, 0-indexed. | 2 | 1 3 2 3 1 |
| The \$n\$th number in the pyramid, 1-indexed. | 7 | 3 |
| The \$n\$th number in the pyramid, 0-indexed. | 7 | 2 |
## Rules
* Please specify which of the above methods your answer uses.
* Output format is highly flexible. It may take the form of your language's collection type, for instance.
* [Sequence rules](https://codegolf.stackexchange.com/tags/sequence/info) apply, so infinite output may be in the form of a lazy list or generator, etc.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the answer with the fewest bytes (in each language) wins.
* [Standard loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) are forbidden.
  
[Answer]
# [Python 2](https://docs.python.org/2/), ~~52~~ ~~50~~ 48 bytes
*-1 byte thanks to @loopy walt*
Takes as input an integer \$ n \$ and outputs the \$ n^{th} \$ row. Based on the Wikipedia formula for the Farey sequence.
```
f=lambda n,b=1,d=1:1/d%b*[1]or[d]+f(n,d+n,n-b%d)
```
[Try it online!](https://tio.run/##DcpBDkAwEAXQvVPMRqKMMJaSnkS6aDOKhF9pbJy@vPW732dPmEqJ9vRXUE/gYIXVyiyD1qFdxKW8qOtiA9YOjD7UakpMmUAHKHtsayNMMpq5ojsfeOjPpnw "Python 2 – Try It Online")
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 26 bytes
Returns the \$n\$th row, 0-indexed.
```
1 1{x?[;;y]/|&y=+':x}/2+!:
```
[Try it online!](https://ngn.codeberg.page/k#eJxLszJUMKyusI+2tq6M1a9Rq7TVVreqqNU30la04uJKU1c0BQCqEQji)
A very literal implementation of the construction described in the challenge.
`2+!:` Integers from 2 to input+1. These are the row numbers to insert.  
`1 1{...}/` Using `1 1` as a seed, reduce the range of integers left to right.
`+':x` Sums of adjacent elements in the last row. The first value in the result will be 0+ first value.  
`&y=` Indices where this is equal to the new row number.  
`|` Reverse the list of indices. We will insert the row numbers one after the other, inserting from left to right would mess up later indices.  
`x?[;;y]/` Starting with the last row, insert the new row number at each of the indices.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
!:Żg$$fR
```
A monadic Link that accepts a positive integer, \$n\$, and yields the \$n\$th row as a list of positive integers.
**[Try it online!](https://tio.run/##y0rNyan8/1/R6ujudBWVtKD///@bAQA "Jelly – Try It Online")**
### How?
```
!:Żg$$fR - Link: integer, n                  e.g. 4
!        - factorial (n)                          24
     $   - last two links as a monad - f(x=n!):
    $    -   last two links as a monad - f(x):
  Ż      -     zero-range (x)                     [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]
   g     -     (that) greatest common divisor (x) [24, 1, 2, 3, 4, 1, 6, 1, 8, 3, 2, 1,12, 1, 2, 3, 8, 1, 6, 1, 4, 3, 2, 1,24]
 :       -   (x) integer divide (that)            [ 1,24,12, 8, 6,24, 4,24, 3, 8,12,24, 2,24,12, 8, 3,24, 4,24, 6, 8,12,24, 1]
       R - range (n)                              [ 1, 2, 3, 4]
      f  - filter keep                            [ 1,                4,    3,          2,          3,    4,                1]
                                                = [ 1, 4, 3, 2, 3, 4, 1]
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 26 bytes
```
Denominator@*FareySequence
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n6Zg@98lNS8/NzMvsSS/yEHLLbEotTI4tbA0NS859b9LfnRAUWZeSXSegq6dQlp0XmysjkJ1no6CIRAZ1Mb@BwA "Wolfram Language (Mathematica) – Try It Online")
Inputs \$n\$ and returns the \$n\$th row, 1-indexed.
---
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 33 bytes
```
1||1//.x_||y_/;x+y<=#:>x||x+y||y&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n6Zg@9@wpsZQX1@vIr6mpjJe37pCu9LGVtnKrqKmBsgEiqn9d8mPDijKzCuJzlPQtVNIi86LjdVRqM7TUTDUUbCojf0PAA "Wolfram Language (Mathematica) – Try It Online")
---
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 39 bytes
```
Cases[#!/GCD[Range[0,#!],#!],a_/;a<=#]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n6Zg@985sTi1OFpZUd/d2SU6KDEvPTXaQEdZMRaME@P1rRNtbJVj1f675EcHFGXmlUTnKejaKaRF58XG6ihU5@koGOooWNTG/gcA "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [Julia 0.7](http://julialang.org/), ~~40~~ 39 bytes
```
!n=(a=(p=lcm(1:n))./gcd.(p,0:p))[a.<=n]
```
[Try it online!](https://tio.run/##BcHBCoAgDADQX5m3DcLyVEj7kuggWrGwNaK@3947vyppbM0pY2I0rvnCEJXI90cuHq0bohEtyc@sa9vvBwQYQpzAHtG3Kjoh2LS0Hw "Julia 0.7 – Try It Online")
Thanks to alephalpha for a saved byte.
[Answer]
# [PARI/GP](https://pari.math.u-bordeaux.fr), 35 bytes
```
n->[d|i<-[0..n!],n>=d=n!/gcd(n!,i)]
```
Inputs \$n\$ and returns the \$n\$th row, 1-indexed.
[Attempt This Online!](https://ato.pxeger.com/run?1=m728ILEoMz69YMHiNAXbpaUlaboWN5XzdO2iU2oybXSjDfT08hRjdfLsbFNs8xT105NTNPIUdTI1Y2FK0_KLNPIUbBUMdRQsdBQKijLzSoB8JQVdOyCRppGnqakJUbpgAYQGAA)
[Answer]
# JavaScript (ES10), 61 bytes
Returns the \$n\$-th row (1-indexed), as an array.
This version naively builds all rows up to the requested one.
```
f=(n,a=[r=1,1])=>r++<n?f(n,a.flatMap(v=>n+(n=v)^r?v:[r,v])):a
```
[Try it online!](https://tio.run/##FYxBCoMwEADvvmJvZkkamqu6@oK@QCwEa4oiuxIll9K3p@lphjnM5pM/57ge143lteQcSLHxNEZyxk1IfdS64yH8qw27vx7@UIl61oop4TMOqRmjSRNi43OQqBgIXAsMXeG9iNYInwpgFj5lX@wub1V@aDdZWdVQI7bVN/8A "JavaScript (Node.js) – Try It Online")
---
# JavaScript (ES6), 43 bytes
*-1 thanks to [@loopywalt](https://codegolf.stackexchange.com/users/107561/loopy-walt)*
Returns the \$n\$-th row (1-indexed), as a comma-separated string.
This is a port of [dingledooper's answer](https://codegolf.stackexchange.com/a/254437/58563).
```
f=(n,b=n,d=1)=>n*~d+b?d+[,f(n,d+n,n-b%d)]:1
```
[Try it online!](https://tio.run/##DYtBDoIwEADvvGIvJl23GHsVVx5iOFCWEg3ZNWC8EPl66Wkmmcy7//XrsLw@31pNxpwTO/WR1QsH5Ieed6HYCj19KkFIvdbxJNjdQk62OAWG0IDCvfBahAhhqwAG09Xm8TLb5MqK2FT/fAA "JavaScript (Node.js) – Try It Online")
[Answer]
# Excel (ms365), 163 bytes
[![enter image description here](https://i.stack.imgur.com/4wtTV.png)](https://i.stack.imgur.com/4wtTV.png)
Formula in `B1`:
```
=IFERROR(REDUCE({1,1},SEQUENCE(A1,,2),LAMBDA(a,b,VSTACK(a,LET(x,TAKE(a,-1),y,DROP(x,,-1),HSTACK(TOROW(VSTACK(y,IF(y+DROP(x,,1)=b,b,NA())),2,1),TAKE(x,,-1)))))),"")
```
---
I designed this answer to be complient with the rule:
> 
> *"The first n rows of the pyramid, 0-indexed. We must be able to tell the rows apart somehow."*
> 
> 
> 
---
The idea here is as follows:
* `REDUCE({1,1},SEQUENCE(A1,,2),LAMBDA(a,b,` - This bit is basically telling Excel to take the input `{1,1}` and recurse the following `SEQUENCE(A1,,2)` times where 'the following' consists of two these two variables. The iteration will now start;
* `VSTACK(a,` - The iteration will then `VSTACK()` (vertically build) what is in variable 'a' and stack the following to it;
* `LET(x,TAKE(a,-1),y,DROP(x,,-1),HSTACK(TOROW(VSTACK(y,IF(y+DROP(x,,1)=b,b,NA())),2,1),TAKE(x,,-1)))` - Bulk of the iteration where we use `LET()` to store the last row from 'a' variable, then take all columns but the last and another variable to take all columns but the first. We compare these two arrays to test if the summation of each element would equal 'b' variable. If so, then use array modification to stack these numbers into the correct location.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~13~~ 9 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
-4 bytes porting [*@JonathanAllan*'s Jelly answer](https://codegolf.stackexchange.com/a/254446/52210), also outputting the \$n^{th}\$ row based on input \$n\$ (so make sure to upvote him as well!):
```
!ÐÝδ¿÷ILÃ
```
[Try it online](https://tio.run/##ARwA4/9vc2FiaWX//yHDkMOdzrTCv8O3SUzDg//Dr/80) or [verify the first 8 rows](https://tio.run/##ASkA1v9vc2FiaWX/OEVOPyIg4oaSICI/Tv8hw5DDnc60wr/Dt05Mw4P/w68s/w). (The footer `ï` casts strings to integers, so the output looks better. Feel free to remove it to see the outputs as strings.)
**Explanation:**
```
!         # Get the factorial of the (implicit) input-integer
 Ð        # Triplicate it
  Ý       # Pop one, and push a list in the range [0,input!]
   δ      # Apply double-vectorized, mapping over the list using another input! as
          # argument:
    ¿     #  Get the greatest common divisor of the current value and input!
     ÷    # Integer-divide the third input! by each of these GCD's
      IL  # Push a list in the range [1,input]
        Ã # Only keep those values from the list
          # (after which the result is output implicitly)
```
**Original 13 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage) approach that outputs the infinite sequence (although pretty slowly):**
```
X‚[=Dü+.ιNÌLÃ
```
[Try it online.](https://tio.run/##yy9OTMpM/f8/4lHDrGhbl8N7tPXO7fQ73ONzuPn/4fX/AQ) (The footer `ï` casts strings to integers, so the output looks better. Feel free to remove it, and change integer `X` to a literal string `1`, to see the outputs as strings.)
**Explanation:**
```
X             # Push a 1
 ‚            # Pair the top two values together. Since the stack only contains a single
              # item and there is no input, it uses it twice to create pair [1,1]
  [           # Start an infinite loop:
   =          #  Print the current list with trailing newline (without popping the list)
    D         #  Duplicate the list
     ü        #  For each overlapping pair:
      +       #   Sum them together
       .ι     #  Interleave the two lists together
         N    #  Push the 0-based loop index
          Ì   #  Increase it by 2
           L  #  Pop and push a list in the range [1,index+2]
            Ã #  Only keep those values from the list
```
[Answer]
# [Nibbles](http://golfscript.com/nibbles/index.html), 14 bytes (28 nibbles)
```
`.:1 1|;>>+!!:0$@+@:-+<2@
```
Returns the infinite sequence of rows.  
Follows the steps in the challenge description.
```
`.:1 1|;>>+!!:0$@+@:-+<2@
`.                          # iterate until unique
  :1 1                      # starting with a list of 1,1
      |;>>+!!:0$@+@:-+<2@   # this function:
           !       :        #   join each element of 
                  @         #   this list
            !:0$@+          #   to pairwise sums of this list (with initial 1),
          +                 #   flatten this list of lists,
        >>                  #   and remove the initial 1;
       ;                    #   (remember this list)
      |                     #   now filter this list 
                            #   keeping only elements that are >0 (truthy) after
                    -       #   subtracting from
                     +      #   the sum of
                      <2@   #   the first two elements of the remembered list
```
[![enter image description here](https://i.stack.imgur.com/w9cg8.png)](https://i.stack.imgur.com/w9cg8.png)
[Answer]
# [Haskell](https://www.haskell.org/), 56 bytes
```
scanl(!)[1,1][2..]
(a:b:t)!i=a:[i|a+b==i]++(b:t)!i
x!i=x
```
[Try it online!](https://tio.run/##JcqxCsMgEIDhPU@hZFFsA3YU7kmsw0VqcvQiEjNk6LP3Guj6f/@K/f1ilgJP6RkrG22jv/kUH9OUBoNhDofVBBgifdDNAJScM/86nJecsiFVBartVA9VhEYGvh5y3o6k@ZsL49Llnlv7AQ "Haskell – Try It Online")
Is an infinite list of rows.
If not valid output [this](https://tio.run/##JcqxDsIgEIDhvU8B6QJBm@BIek@CDFcUvXgSUjp08Nk9m7j@3//E/rozS4Gr0A3muWesbLSN/uRTvExTGgyGJWxWE2CI9EG3AFByzvzrsB@yyxupKlBtpbqpIjQy8PGQ83Ykzd9cGB9dzrm1Hw "Haskell – Try It Online") is an infinite list of numbers for 61 Bytes.
```
id=<<scanl(!)[1,1][2..]
(a:b:t)!i=a:[i|a+b==i]++(b:t)!i
x!i=x
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 9 bytes
```
¡Dʀvġḭ?ɾ↔
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLCoUTKgHbEoeG4rT/JvuKGlCIsIiIsIjQiXQ==)
Port of [Jonathan Allan's Jelly answer](https://codegolf.stackexchange.com/questions/254429/prime-pyramid/254446#254446)
```
¡D        # n!, 3 times
   vġ     # Gcd with
  ʀ       # Range(0, n+1)
     ḭ    # Integer divide n by that
      ?ɾ↔ # Keep those from range(1, n+1)
```
[Answer]
# [Python](https://www.python.org), 73 bytes
```
a=x,=1,
while[print(1,*a)]:a=sum(([x+y][x+y+~a[0]:]+[x:=y]for y in a),[])
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vwYKlpSVpuhY3PRNtK3RsDXW4yjMyc1KjC4oy80o0DHW0EjVjrRJti0tzNTSiK7QrY0GEdl1itEGsVax2dIWVbWVsWn6RQqVCZp5CoqZOdKwmxECouTDzAQ)
Prints forever.
Naive implementation. Feel a bit silly, since everybody else seems to do something clever.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 27 bytes
```
Ｎθ⊞υ¹Ｗ⁼¹№υ¹⊞υ⁻θ﹪⁺θ§υ±²↨υ⁰Ｉυ
```
[Try it online!](https://tio.run/##NY29DsIwDIR3niKjIwWJIjExQcXQgaqvYNqIRApJ82Pg7YOjiu2@8915NpjmgK7Wwa9URno9dIIoz7uJsgFSomP9MdZpAbdI6DJ0SvSBfNmuUop/9G49ZYgswkIuwOQ2vJTBL/rbIqN@YtFw5JoSV8y6mQem9jFZHu0x8zJzrae6f7sf "Charcoal – Try It Online") Link is to verbose version of code. Outputs the `n`th row. Explanation: Based on @dingledooper's formula.
```
Ｎθ
```
Input `n`.
```
⊞υ¹
```
Start with `1` as the first term in the `n`th row.
```
Ｗ⁼¹№υ¹
```
Repeat until there are two `1`s in the row.
```
⊞υ⁻θ﹪⁺θ§υ±²↨υ⁰
```
Calculate the next term as `n-(n+b)%d` where `d` is the previous term and `b` is the penultimate term. Note that on the first loop there is no penultimate term so cyclic indexing gives `b` a value of `1` but `d=1` so the result is `n` anyway.
```
Ｉυ
```
Output all of the terms in the `n`th row.
A naive approach takes 34 bytes:
```
Ｆ²⊞υ¹Ｆ…·²Ｎ≔ΣＥυΦ⟦ικ⟧∨ν∧λ⁼ι⁺κ§υ⊖λυＩυ
```
[Attempt This Online!](https://ato.pxeger.com/run?1=NY49CkIxEIR7T7FYbSAWCoJgJf7AK9SHlmIRY9Rg3qpJVryLjYKircfxNsa_7Wa_mWGOd71SXm-UO52uHBeVxvOx2HjAmoCcwwpZQlU0S59fRtpxsHszUrQ0WJOQ0ZbjgIuZ8SiEgFYIdkk45gL7avsO96yLCU6shPVUwtAjSWjRHJ2E7o6VC5hQnnpxnUDMaG4O72DHaG8KQ9Ekr_ifBE5rcm8pYluFiCxE8xJmOvzm3yblyt6Vp-f6V78A "Charcoal – Attempt This Online") Link is to verbose version of code. Outputs the `n`th row. Explanation:
```
Ｆ²⊞υ¹
```
Start with `[1, 1]` as the first row.
```
Ｆ…·²Ｎ
```
Loop over the remaining rows.
```
≔ΣＥυΦ⟦ικ⟧∨ν∧λ⁼ι⁺κ§υ⊖λυ
```
Insert the current row number into the list at the appropriate places.
```
Ｉυ
```
Output the final list.
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 71 bytes
```
.+
$*
1
,1$`
^
1,1¶
{`\b(1+)(?=(,1+)\b.*¶\2\1\b)
$1$2$1
}`¶,1+
¶
1+
$.&
```
[Try it online!](https://tio.run/##K0otycxL/K@nzaWidWgbF5eKXgKXoWMCl6qGewJElMuQS8dQJYErjstQxxCopDohJknDUFtTw95WQwdIxyTpAXXGGMUYxiRpcqkYqhipGHLVJhzaBpTkAqoHkip6av//mwEA "Retina 0.8.2 – Try It Online") Outputs the `n`th row but link is to test suite that outputs the first `n` rows. Explanation:
```
.+
$*
```
Convert `n` to unary.
```
1
,1$`
```
Create a list from `1` to `n`.
```
^
1,1¶
```
Start with `[1, 1]` as the first row.
```
{`
}`
```
Loop over each row.
```
\b(1+)(?=(,1+)\b.*¶\2\1\b)
$1$2$1
```
Insert the current index between every pair of adjacent values with that as its sum.
```
¶,1+
¶
```
Remove the current index so that the next loop uses the next index.
```
1+
$.&
```
Convert to decimal.
[Answer]
# [Haskell](https://www.haskell.org/), 63 bytes
```
scanl(#)[1,1][2..]
(a:t@(b:_))#r|r==a+b=a:r:t#r|0<1=a:t#r
l#_=l
```
The first line generates a lazy infinite list of rows. [Try it online!](https://tio.run/##DcexCsIwEADQvV8RiEOCWoxj8MB/cKylXEO1xWsMuRQXv91423sz8msiqisuUYFKW7mVrHZqi7TEiUUrJsXz@yO8Vw4YyWjbuYPru3Pb9o1BX65m9IO1On8zAO5HQJ99kZ4uTixqSA9Atf7Cg/DJ9RhS@gM "Haskell – Try It Online")
### Explanation
The core of the solution is the operator `#`, which takes a list of numbers (the previous row) and an integer (the next row number) and recursively computes the next row.
```
-- If the first argument is a list with at least two elements, unpack it as
-- follows: first element is a, all but first element is t, second element is b
-- Second argument is r
(a:t@(b:_)) # r
-- If r equals a+b, prepend a and r to the result of a recursive call on t
  | r == a+b  = a:r:(t#r)
-- Else, just prepend a
  | otherwise = a:(t#r)
-- If the first argument has fewer than two elements, return it unchanged
l # _ = l
```
Then, to generate the infinite list of rows, we start from `[1,1]` and do a left scan over increasing row numbers:
```
scanl (#) [1,1] [2..]
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 24 bytes
```
JU2VQ
=-.iJm*qhNdd+VtJJ0
```
[Try it online!](https://tio.run/##K6gsyfj/3yvUKCyQy1ZXL9MrV6swwy8lRTusxMvL4P9/SwA "Pyth – Try It Online")
Prints the first \$n\$ rows as lists.
### Explanation
```
JU2                        assign J to [0, 1]
   VQ                      for N in range eval(input())
                           print
     =   J                 assign J to
      -               0    remove zeros from
       .iJ                 interleave J with
          m*qhNdd          if not N map to 0
                 +VtJJ     pairwise sums of J
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 82 bytes
```
o;g(n,b,d){o=n*~d+b?asprintf(&o,"%d %s",d,g(n,d+n,n-b%d)),o:"1";}f(n){n=g(n,n,1);}
```
[Try it online!](https://tio.run/##LY3BCgIhGITv@xQiGP75L@Q1V3qRLqviItRvrEGHZXv0TKM5zGG@GcaPi/e1ZrNIQocBtmzp@A7KXebyWBM9ozxk5CIwUTgG7L2gCGl0IgBgPnPNzR4lwUa2U0INZq9tyu5zIgnDNrCmmFcme5qsNixN@tRcKfjBrv8dF@VKHFmUCcAMe/34eJuXUsfXFw "C (gcc) – Try It Online")
C port of dingledooper's answer.
[Answer]
# [Ruby](https://www.ruby-lang.org/), 40 bytes
This is a port of [dingledooper's answer](https://codegolf.stackexchange.com/a/254437/58563) and [Arnauld's answer](https://codegolf.stackexchange.com/a/254431/112099).
```
->n,b,d=1{b+n*~d<0?[d,f[n,d+n,n-b%d]]:1}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsHiNNuYpaUlaboWNzV07fJ0knRSbA2rk7TztOpSbAzso1N00qLzdFK083TydJNUU2JjrQxroeoVNAz19PQMDTT1chMLqrk4CxTSouMNdeINY7WUdBSUuKDqFiyA0AA)
[Answer]
# [Zsh](https://zsh.sourceforge.io/), 92 ~~100~~ bytes
```
p=(1 1)
for j ({2..$1})<<<$p&&p=(`for i ({1..$#p})echo $p[i] ${$((p[i]+p[i+1]==j?j:0)):#0}`)
```
[Try it Online!](https://tio.run/##FclBCoAgEEDRfacYcAgHIZyWonSQEIIozE1Su8KzT7b5fHjPnURK0AxM3X5ekEG/4zAgV/LeY@n7pssvRxNuokqlbU0nYJmPCPii1v@ZFsMxhDxlZ4mcsnUhEeHxAw)
... ~~[100 bytes](https://tio.run/##FcmxCoQwDIDh/Z4iYIYGQRpHr8UHUaGT2A5e8G660mePcfn54ft/D1WJjoHpvX8uKODqOAzIjWoIAeVlmh7JJmzSiZFc@fztgLLkbQWs6NyzvaXnLcYyl8kTTZ1vK7RETVV5vAE)~~
]