[Question]
  [
Output the flattened version of the sequence [A297359](http://oeis.org/A297359), which starts like the following:
```
1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 2, 4, 6, 4, 2, 1, 6, 10, 10, 6, 1,
1, 7, 16, 20, 16, 7, 1, 3, 8, 23, 36, 36, 23, 8, 3, 3, 11, 31, 59,
72, 59, 31, 11, 3, 1, 14, 42, 90, 131, 131, 90, 42, 14, 1,...
----------------
                  1,
                1,   1,
              1,  2,   1,
            1,  3,   3,  1,
          2,  4,  6,   4,  2,
        1,  6,  10, 10,  6,  1,
      1, 7,  16,  20,  16,  7, 1,
    3, 8,  23,  36, 36,  23,  8, 3,
  3, 11, 31, 59,  72,  59, 31, 11, 3,
1, 14, 42, 90, 131, 131, 90, 42, 14, 1,
...
```
The defining property of the sequence is that
* the entire triangle is generated like the Pascal's triangle (i.e. each entry inside the triangle is the sum of the two numbers above it), and
* the left and right boundaries are identical to the entire triangle read by rows.
Standard [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") rules and [sequence](/questions/tagged/sequence "show questions tagged 'sequence'") I/O methods apply. See <https://codegolf.stackexchange.com/tags/sequence/info> and <https://codegolf.stackexchange.com/tags/code-golf/info>.
The shortest code in bytes wins.
  
[Answer]
# [Haskell](https://www.haskell.org/), 61 bytes
```
1:t
r!b=b:zipWith(+)r(tail r)++[b]
t=1:tail(scanl(!)[]t>>=id)
```
[Try it online!](https://tio.run/##PU1BDoIwELzzipJwoKEmFBGEpHzDA3IooNJYCWl78vHWbSsmuzuzM5vZhevnTUqr2dXS1kQqHtnYvsV2EWZJM6xSw4VECmdZPw6RYXAEQqonvso0xv1guo6JGdsXFyvblFhNwtc52SMYwxr1lKB/FTs5@gpKSVDlZ3CB0zy0owSkGhB4kQes94gzaC6pCl0E6ZftTqBPDakLD36ldP9M4WMJTuNSveWG25zqXDrYz3SX/KHtYdq2Lw "Haskell – Try It Online")
Feels a bit clunky, and frankly I'm not entirely sure I understand what I've done with both of those explicit leading ones.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~14~~ 13 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
λε=Dˆ}ü+¯Nè.ø
```
Infinitely outputs each integer on a separated line.
-1 byte thanks to *@ovs*.
[Try it online.](https://tio.run/##ASgA1/9vc2FiaWX//867zrU9RMuGfcO8K8KvTsOoLsO4////LS1uby1sYXp5)
**Explanation:**
```
λ          # Create a recursive environment,
           # starting with a(0)=1 by default
           # And we calculate every following a(n) as follows:
 ε         #  Map over the integers in the current list (or the digit(s) of the 1):
  =        #   Print the current integer with trailing newline (without popping)
   Dˆ      #   Add a copy of the integer to the global array
 }ü        #  After the map: map over the overlapping pairs:
   +       #   And sum them together
    ¯Nè    #  Index `n` of the recursive environment into the global array
       .ø  #  And surround the list with this integer as leading/trailing item
```
[Answer]
# [Python 3](https://docs.python.org/3/), 94,93(@xnor),88(use infinite generator),83(smarter buffering),79(obvious saving),67 bytes(@dingledooper)
```
*P,z=p=1,1
for x in P:print(z);z,*q=p;p=x,*map(sum,zip(p,q)),x;P+=p
```
[Try it online!](https://tio.run/##BcExDoAgDAXQ3VMwAnYhbpLegSu4GBmAD2qCvXx9D99ztbqp@kTC4EBhOdsw0@Rq0o6R62PFRSHfGRE8yZcD9n4LSYYFdedoxrQyVPUH "Python 3 – Try It Online")
I doubt this is competitive, but there is only one way to find out...Beginning to get the hang of it.
The code works row-by-row (the computation, output is element by element) and is pretty straight-forward, the only mildly tricky thing being that the for loop actually sees the intermittent updates of the P list (This relies on `+=` actually being equivalent to `.extend` which also allows us to be a bit cavalier with list vs tuple). And perhaps the backwards-in-time order of assignments towards the yieldprint statement whose effect is a two-cycle-buffering (z is the x from two iterations ago).
[Old version](https://tio.run/##Jc2xDoMgEADQ3a@4EegN1W4a/sHdODQV0kvEO4EmyM/TJh3f9OTKbz4erW3Og1d67MDMWK3YwSz92oHnCAXogHm8yO0b1KmiOa1MYgua8BSVPgEriRI8tcYyzTcrzUcOQNnFzLwnoCAcM1Da6eU6iXRktZg/1e/FfrjrVbf2BQ "Python 3 – Try It Online")
[Old version](https://tio.run/##Jc2xCsMgEADQPV9xo9obYrsZ/IfsQUpplB5oPIyBxJ@3hY5venzVT94eva8@QBDSDKBmbJbtXS3aDRBygRNog9lc5OMKbWqonpYntieq9GKxHwkbsWDkRRsnJZ7TfLPcQ8kJqPpSc447UOJcKtAe6e0HLrRVsag/xe9GPY7Syd6/ "Python 3 – Try It Online")
[Old version](https://tio.run/##Lc6xDsIgFEDRna94I1QGWzca/oGdMBgL8SVQXoAm1J9Ho453OMmlsz3zfhtj8wECF4qB0XZ2K@llMuuJPm4QSk5ADEIu0AF3MIp0l1O6E69Hki8kTpLsrJwQsq/moulP@/hibL60nGMFTJRLA6wRH55Rwb1xO)
[Old version](https://tio.run/##FcgxDsMgDADAnVd4xMQL6UbEBzJ5j6KqUoPKEOJQItF@3lVvPPm011Fuqs8tQbIzBgMcF79OEs84OjaQjgp36pALfLPY2TExBomd3P4Q@752@r@QLD6siNQnHqIYqFu7aoFzYKNSc2k2WT8iqv4A "Python 3 – Try It Online")
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 72 bytes
```
f=(n,l=0,a=[],x)=>a[n]||(n<2?1:f(n-l,a.push(x),a.map(m=>x+(x=m)||f(l))))
```
[Try it online!](https://tio.run/##LYxBDoIwEEX3nsId01BINa4sgwchLCZItaSdElDTRe9eG@NfvcV7f6EP7dNm11fD4T7nbBBYOlSScBhlFNjTwGNKwN35droa4MZJatf3/oQoCnlawWMfa4joRUoGnCjLJmzw@7CotO0uSv8rA7aui0H6MAXeg5tbFx5A7RIsQyWPlRA6fwE "JavaScript (Node.js) – Try It Online")
---
# [JavaScript (Node.js)](https://nodejs.org), 74 bytes
```
f=(n,q=(n*8+1)**.5,r=q-1>>1)=>n>1?(n*8+9)**.5%1&&q%1?f(n+~r)+f(n-r):f(r):1
```
[Try it online!](https://tio.run/##HclBDoIwEEDRvadwA8y0pWESTdTachDjokGqJaSFoi69eiVs3l/8wX7t0iU/vesQH33OTkMQ8wo7cULG5FEkPddkDKE2wVC7rfO2CirLuaDWQeC/hHxtnfDiYIWyiwmsvt2F143y10OjrJw@ywsceM4R0apdF8MSx16O8QlWDtEHqMS@QlT5Dw "JavaScript (Node.js) – Try It Online")
I have no idea whether following 70 byte version works or not. If you can prove its correctness or find out failed testcases, please leave a comment here:
```
f=(n,q=(n*8+1)**.5,r=--q>>1)=>n>1?q%2<2-2/r&&q%2?f(n+~r)+f(n-r):f(r):1
```
[Try it online!](https://tio.run/##DcZLDsIgFEDRufuwfa98BBITI4UuxDggtShNAy1Vh24dmZx7Z/d1@5jD@mYxPaZSvIFIt0p3IRK7jp9pNoxt1ko0Nlo5bEfVK6ZOuWnqDh4i@WUktSzj1UNFFp8yOHO702CEDr0UQju@fvYXeAiEIKLThzHFPS0TX9ITHJ9TiNDSFrH8AQ "JavaScript (Node.js) – Try It Online")
[Answer]
# [Appleseed](https://github.com/dloscutoff/appleseed), 127 bytes
```
(def T(q(((R(q(1)))(S(concat(q(1 1 1))(drop 4(T)))))(concat R(T(cons(head S)(insert-end(head S)(zip-with add(tail R)R)))(tail S
```
Defines a function `T` that takes no arguments and returns the sequence as an infinite list. [Try it online!](https://tio.run/##PY3BCgMhDER/Jb2Nhz0U@iXqvaSblBWsa1Uo9OetbkszECZvIMM5R62q0jtE7@TxBGDHPhtj4LDuaeU2bxoaSMqe6QJv5vxisvDTVmzKQs4gpKqlLZrkj94hL6/QNmIRNA6RrLHzx@Hdt782Lu1EiPy4CdOVkEtIkxyF/QM "Appleseed – Try It Online")
### Ungolfed + explanation
```
(def TriSeq
  (lambda
    ((Row (q (1)))
     (Seq (concat (q (1 1 1)) (drop 4 (TriSeq)))))
    (concat Row
      (TriSeq
        (cons (head Seq)
          (insert-end (head Seq)
            (zip-with add (tail Row) Row)))
        (tail Seq)))))
```
`TriSeq` builds the sequence one triangle row at a time. It takes two optional arguments: `Row`, the current row, and `Seq`, the sequence up to this point. The first row is the default value for `Row`, `(q (1))`, a list containing a single 1. After that, the interior portion of the next row is calculated from `Row` by `(zip-with add (tail Row) Row)`. The exterior numbers come from the next element in the sequence, `(head Seq)`. `Seq` is initialized by its default value, `(concat (q (1 1 1)) (drop 4 (TriSeq)))`. Conceptually, this is:
```
(1 1 1 1 2 1 1 3 3 ...)   ; (TriSeq) (a recursive call with lazy evaluation)
(2 1 1 3 3 ...)           ; (drop 4 (TriSeq))
(1 1 1 2 1 1 3 3 ...)     ; (concat (q (1 1 1)) (drop 4 (TriSeq)))
```
We don't need the first 1 in the sequence because it's supplied by the default value for `Row`. We have to do the `drop`/`concat` routine because the first few values of the sequence are self-referential, and Appleseed will get into an infinite recursion trying to calculate them unless we specify them explicitly.
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~85..~~ 72 bytes
```
*l=1
1.step{|i|p *l[-i,i]
l+=[m=l[i]||1,*(-i..-2).map{|j|l[j,2].sum},m]}
```
[Try it online!](https://tio.run/##KypNqvz/XyvH1pDLUK@4JLWguiazpkBBKydaN1MnM5YrR9s2Otc2JzoztqbGUEdLQzdTT0/XSFMvNxGoMqsmJzpLxyhWr7g0t1YnN7b2/38A "Ruby – Try It Online")
* Thanks to @Dingus for the 5 Bytes saved!
Full program, outputs the sequence indefinitely vertically.
```
*l=1       # we start with [1]
1.step{|i| # iterate i starting from 1(i is the boundary position == triangle line length)
p *l[-i,i] # puts last i elements 
l+=[...]   # append new triangle line :
[m=l[i]||1   #[ m=boundary || 1 because initially not available 
*            #, splat inner elements :
(-i..-2).map{  #* range of last i pos. 
|j|l[j,2].sum} #* take 2 and sum
m            # right bound]
} repeat indefinitely 
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 47 bytes
```
ＮθＦ³⊞υ¹≔…υ²ηＷ‹Ｌυθ«⊞η⁻§υＬη§υ⊖ＬηＵＭη⁺κ§η⊖λ≔⁺υηυ»Ｉυ
```
[Try it online!](https://tio.run/##VY7NDoIwEITP8hQ9tgke1HDiRPBCIoZXqLBSYlugP/7E@Ox1ISToHvYwM99kasFN3XMZQqEH785eXcDQkaXRtTeEHhipvBXUx2SHWmZt12qav2oJueiHSd@zmAj0HqKTQOgJrMWnW4cUWiNj5B1t5hYRk7LT3tLMFbqB54QvUcEw@yMfoTagQDto6BrBS6NNyYe8V4rrZmqsJBbeVlj8w3KBlulz2k@LY@JR/0SV6bSjObcO97I0hCQJ27v8Ag "Charcoal – Try It Online") Link is to verbose version of code. Outputs the first `n` terms. Explanation:
```
Ｎθ
```
Input `n`.
```
Ｆ³⊞υ¹
```
Start the flattened list with the first three terms.
```
≔…υ²η
```
This corresponds to having already generated the second row.
```
Ｗ‹Ｌυθ«
```
Repeat until sufficient terms have been collected.
```
⊞η⁻§υＬη§υ⊖Ｌη
```
Push the difference between the next two terms to the row. (Normally Pascal's Triangle just needs `0` pushed here, but this makes the row ends follow the sequence itself.)
```
ＵＭη⁺κ§η⊖λ
```
Generate the next row of the triangle.
```
≔⁺υηυ
```
Accumulate it to the flattened list.
```
»Ｉυ
```
Output the first `n` terms.
[Answer]
# [Raku](http://raku.org/), 60 bytes
```
my@a=flat(1,<1 1>,{@a[++$+1],|(.[1..*]Z+@$_),@a[++$+1]}...*)
```
[Try it online!](https://tio.run/##K0gtyjH7/z@30iHRNi0nsUTDUMfGUMHQTqfaITFaW1tF2zBWp0ZDL9pQT08rNkrbQSVeUwcuU6sHFNX8b61QnFipABSNMzQwiP0PAA "Perl 6 – Try It Online")
This is a lazy, self-referential, infinite list, stored in the variable `@a`. The expression inside the `flat` is a sequence of rows, where `.[1..*] Z+ @$_` generates the inside sums (by addition-zipping the row with itself without its first element), and the endpoints are taken from the flattened outer array `@a`. The two lone `$`s are anonymous state variables that start off undefined/zero, so the first time the generator block is entered for the third row, the endpoints `@a[++$+1]` are `@a[2]`, when the fourth row is generated the endpoints are `@a[3]`, etc.
[Answer]
# [R](https://www.r-project.org/), ~~89~~ 85 bytes
*-4 bytes thanks to [@Giuseppe](https://codegolf.stackexchange.com/users/67312/giuseppe)*
```
function(n){s=r=!!1:2
for(i in 2:n)s=c(s,r<-c(s[i],r[-1]+head(r,-1),s[i]))
c(1,s)[n]}
```
[Try it online!](https://tio.run/##Fc0xCsMwDEDRPadwNonIUAWymPgkxkNwG2oISpDSoZSe3W2mD2/52kxPi219STnrLiD4saix7zmM3borVFfFjUHQYgEjnf0/qWbS5DkPz8dyByXPSJcidgWYDJPkb7PlOLY3cJhu5K4Rth8 "R – Try It Online")
Function returning 1-indexed element of the sequence. Uses simple loop to create consecutive rows of the triangle.
]