[Question]
  [
We are going to fold a list of integers. The procedure to do so is as follows, If the list is of even length, make a list of half of its length where the nth item of the new list is the sum of the nth item of the old list and the nth-to-last item of the old list. For example if we had the list
```
[1 2 3 4 5 6 7 8]
```
We would fold it like so
```
 [8 7 6 5]
+[1 2 3 4]
__________
 [9 9 9 9]
```
If the list is of *odd* length, to fold it we first remove the middle item, fold it as if it were even and the append the middle item to the result.
For example if we had the list
```
[1 2 3 4 5 6 7]
```
We would fold it like so
```
 [7 6 5]
+[1 2 3]
__________
 [8 8 8]
++     [4]
__________
 [8 8 8 4]
```
## Task
Write a program or function that takes a list of integers as input and outputs that list folded.
This is a [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") question so answers will be scored in bytes, with fewer bytes being better.
## Sample implementation
Here's an implementation in Haskell that defines a function `f` that performs a fold.
```
f(a:b@(_:_))=a+last b:f(init b)
f x=x
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P00j0SrJQSPeKl5T0zZROyexuEQhySpNIzMvE8jQ5EpTqLCt@J@bmJlnW1CUmVeikhZtqGOkY6xjomOqYxb7HwA "Haskell ‚Äì Try It Online")
  
[Answer]
# [Python](https://docs.python.org/2/), 46 bytes
```
f=lambda l:l[1:]and[l[0]+l[-1]]+f(l[1:-1])or l
```
[Try it online!](https://tio.run/##dYxBCoNAEATPySv6qNgBV5MYF/KSYQ4rskSYrCJe8vpVH5BLU1RBL7/tM6cm5/i28B3GAPMmzmtIo5jUWpncnGoVi1MfWM4rLMdzMSWIIxqiJe7Eg3gSHfFS/itEr/56WdYpbThey7wD "Python 2 ‚Äì Try It Online")
Same length:
```
f=lambda l:l[1:]and[l.pop(0)+l.pop()]+f(l)or l
```
A much shorter solution works for even-length lists (30 bytes)
```
lambda l:[x+l.pop()for x in l]
```
[Try it online!](https://tio.run/##dcnLCkBAGAbQNU/xLcmXcr@UJ2EWpIn6zUyy4OlHHsDu1HHPtVmTez1MXuZjWWdIP96JpM66KNb2xI3dQJT/LJ/HjMiJgiiJiqiJhmgV/4boVB8G7tzNBR1J7F8 "Python 2 ‚Äì Try It Online")
I'm still trying to find a short way to correct it for odd length.
[Answer]
# [Emojicode](http://www.emojicode.org/), 203 bytes
```
üêãüç®üçáüêñüî¢üçáüîÇi‚è©0‚ûóüêîüêï2üçáüòÄüî°‚ûïüç∫üî≤üêΩüêïiüöÇüç∫üî≤üêΩüêï‚ûñüêîüêï‚ûï1iüöÇ10üçâüçäüòõ1üöÆüêîüêï2üçáüòÄüî°üç∫üî≤üêΩüêï‚ûóüêîüêï2üöÇ10üçâüçâüçâ
```
This was the most painful Emojicode answer to code for me. The unnecessary length :/
[Try it online!](https://tio.run/##S83Nz8pMzk9J/f//w/wJ3R/m964A4nYge9qH@VMWQdhTmjIf9a80eDRvOlB8ChBPNYJIzGgASi58NG8qkLsLyNwElNsLks/8MH9WE7rgo3nTYPqBWgzBagwNgKo6gbgLaNpsQ6DQOqx2YJqF7BYkc8AY6Jf@RgWQfgUuBQWQR0CcFQqGCkYKxgomCqYKZgrmIKE2LrByAA "Emojicode ‚Äì Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 5 bytes
### Code
```
2√§`R+
```
Uses the **05AB1E** encoding. [Try it online!](https://tio.run/##MzBNTDJM/f/f6PCShCDt//@jDXUUjHQUjHUUTHQUTHUUzHQUzGMB "05AB1E ‚Äì Try It Online")
### Explanation
```
2√§        # Split the list into two pieces
  `       # Flatten the stack
   R      # Reverse the second element from the list
    +     # Vectorized addition
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~21~~ ~~18~~ 16 bytes
```
l
√≠Uj¬∞V/2V w)mx
```
[Test it online!](http://ethproductions.github.io/japt/?v=1.4.5&code=CmwK7VVqsFYvMlYgdylteA==&input=WzEgMiAzIDQgNSA2IDdd)
~~Completely awful~~ Slightly less awful thanks to [@Oliver](https://codegolf.stackexchange.com/users/61613). BRB after I implement more built-ins and fix some bugs...
[Answer]
# [Gaia](https://github.com/splcurran/Gaia), 7 [bytes](https://github.com/splcurran/Gaia/blob/master/codepage.md)
```
e2√∑ev+‚Ä†
```
### Explanation
```
e        Eval the input (push the list).
 2√∑      Split it in half. The first half will be longer for an odd length.
   e     Dump the two halves on the stack.
    v    Reverse the second.
     +‚Ä†  Element-wise addition. If the first half has an extra element, it is simply appended.
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 7 bytes
```
≈ìs2U2¬¶S
```
[Try it online!](https://tio.run/##y0rNyan8///o5GKjUKNDy4L///8fbaijYKSjYKyjYKKjYKqjYKajYK6jYBELAA "Jelly ‚Äì Try It Online")
-2 thanks to [ETHproductions](https://codegolf.stackexchange.com/users/42545/ethproductions)...and me realizing before.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~55~~ 41 bytes
```
f(_,l)int*_;{for(;l--;*_+++=l?_[l--]:0);}
```
[Try it online!](https://tio.run/##dY7dCoJAFITvfYppQdh1j5D2o7RIDyIhYRjClqLWjfjsdlbpoovuZphv5pwyvJflPFeyIKvq5xAUZqyaThobhiYotNaZPRc5u8tpq8w0v5v6hrZj9Np10jXAgsAKVmH0uA1p4PpqBSsp/JvfC0LAqNYEAaE3VhmvfQ29FILV5D2u9VO6BTc1RPklGyNCTNgR9oQD4UhICOlkViT@g3BeySGi1B34fsp@r5YgpuQniJdgmj8 "C (gcc) ‚Äì Try It Online")
Overwrites the first \$\left\lfloor\frac{l}{2}\right\rfloor\$ entries of the input array.
### [C (gcc)](https://gcc.gnu.org/), 46 bytes
```
f(_,l)int*_;{_=l>1?*_+=_[l-1],1+f(_+1,l-2):l;}
```
[Try it online!](https://tio.run/##dc7LCsIwEAXQfb/iGhCSZrJIfLQYqh@iEqRSKcQqbXVT@u01VUEE3V1mzjxydcrzYSi4Iy/Kqo2d7Vzm13oTO5m5rVd6T1qGvtTklRErb/vhfimPuNbBH@qaj2MIgRASvEAXFZca3MIrZcULFpxNj9OGEeJApSQwMDnxwkbXW9twxkLqo/OhrPi4YVzV6u0@6zTBEGaEOWFBWBISQtrbFzF/SOh/7u4qRgVvNaVCvOvj46EwFz@coeTbmafrhwc "C (gcc) ‚Äì Try It Online")
Additionally returns the length \$\left\lceil\frac{l}{2}\right\rceil\$ of the output.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 4 bytes
```
I√∑·πò+
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCJJw7fhuZgrIiwiIiwiWzEsIDIsIDMsIDQsIDUsIDYsIDddIl0=)
```
I    # Halve the list
 √∑   # Push each half
  ·πò  # Reverse the second half
   + # Add them together (vectorising)
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip), ~~14~~ 12 bytes
```
YCHa;@y+Ry@1
```
-2 Thanks to [DLosc](https://codegolf.stackexchange.com/users/16766/dlosc)!
How?
```
YCHa;@y+Ry@1  : One arg; list
   a          : First input
 CH           : Chop iterable into 2 pieces of roughly equal length
Y             : Yank value
         y    : The two halves
          @1  : Get item/slice at index 1; The second half
        R     : Reverse
       +      : Add with
      y       : The two halves
     @        : Get item at index 0; The first half
```
[Try It Online!](https://dso.surge.sh/#@WyJwaXAiLCIiLCJZQ0hhO0B5K1J5QDEiLCIiLCIiLCInWzE7MjszOzQ7NTs2OzddJyAteCJd)
[Answer]
# [Fig](https://github.com/Seggan/Fig), \$23\log\_{256}(96)\approx\$ 18.932 bytes
```
J+t_HLxxt_HLx$xs_HLxtHL
```
[Try it online!](https://fig.fly.dev/#WyJKK3RfSEx4eHRfSEx4JHhzX0hMeHRITCIsIlsxLDIsMyw0LDUsNiw3XSJd)
\$-26\log\_{256}(96)\approx21.401\$ thanks to [Seggan](https://codegolf.stackexchange.com/users/107299/seggan)
First time using Fig. Any golfing tips are welcome.
### Explanation (outdated):
```
fw+[yfy$fy$fyx[yfy$fy$fy$x?h%1HLx[]yfy$fy$fyx]yW1
   [yfy$fy$fyx                                    First Mid
  +                                               Add
              [yfy$fy$fy$x                        Second Mid
fw                                                Concat
                          ?                       If
                           h%1HLx                 List length is odd,
                                 []yfy$fy$fyx     Mid
                                             ]yW1 Else Empty list
```
[Answer]
# [Thunno 2](https://github.com/Thunno/Thunno2), ~~7~~ 5 bytes
```
2·∫Ü·∫∏r+
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m728JKM0Ly_faMGCpaUlaboWK40e7mp7uGtHkfaS4qTkYqjogvXRhjpGOsY6JjqmOmY65rEQYQA)
```
2·∫Ü·∫∏r+ # implicit input
2·∫Ü    # split list in half
  ·∫∏   # push both halves to the stack
   r  # reverse top one
    + # vectorized addition
      # implicit output
```
[Answer]
# Mathematica, 88 bytes
```
(d=Array[s[[#]]+s[[-#]]&,x=‚åät=Length[s=#]/2‚åã];If[IntegerQ@t,d,d~AppendTo~s[[x+1]]])&
```
[Answer]
## Mathematica 57 Bytes
```
(#+Reverse@#)[[;;d-1]]&@Insert[#,0,d=‚åàLength@#/2‚åâ+1]&
```
Inserts a zero at the midpoint, adds the list to its reverse and takes the appropriate length.
[Answer]
# JavaScript (ES6), 41 bytes
```
f=a=>1/a[1]?[a.shift()+a.pop(),...f(a)]:a
```
```
f=a=>1/a[1]?[a.shift()+a.pop(),...f(a)]:a
console.log(JSON.stringify(f([1,2,3,4,5,6,7,8])));
console.log(JSON.stringify(f([1,2,3,4,5,6,7])));
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 12 bytes
```
√•@o +Y*(Z<Ul
```
[Try it online!](https://codepen.io/justinm53/full/NvKjZr?code=5UBvICtZKihaPFVs&inputs=WzEsIDIsIDMsIDQsIDUsIDYsIDdd,WzEsIDIsIDMsIDQsIDUsIDYsIDcsIDhd,WzEsMiwzLDQsNSw2LDcsOCw5LDEwLDExLDEyLDEzXQ==,WzEsMiwzXQ==,WzUsNCwzLDIsMV0=&flags=LVE=) with the `-Q` flag to view the formatted array.
## Alternate solution, 14 bytes
```
o(¬Ω*Ul)c)√≠U mx
```
[Try it online!](https://codepen.io/justinm53/full/NvKjZr?code=byi9KlVsKWMp7VUgbXg=&inputs=WzEsIDIsIDMsIDQsIDUsIDYsIDdd,WzEsIDIsIDMsIDQsIDUsIDYsIDcsIDhd,WzEsMiwzLDQsNSw2LDcsOCw5LDEwLDExLDEyLDEzXQ==,WzEsMiwzXQ==,WzUsNCwzLDIsMV0=&flags=LVE=)
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 53 bytes
```
x=>x.splice(0,x.length/2).map(y=>y+x.pop()).concat(x)
```
[Try it online!](https://tio.run/##dc3dCoIwGIDhc6/iOwjc6GuV/YLMGzHBsaZNbBu6ZBJd@wrPO37heTsxiVEO2vmNsXcVGx4DLwIbXa@lIjsMrFem9Y9tRtlTODLzYl4H5qwjlDJpjRSeBBrzSQygjXt54FAmAOUeIUM4IBwRTghnhAvCtcI/rUqqPPl5o@0V621LFmx5CuAF1Kt3QwT91JR1VhuS3kxKaR6/ "JavaScript (Node.js) ‚Äì Try It Online")
Another suggestion: 
# [JavaScript (Node.js)](https://nodejs.org), 43 bytes
```
f=x=>x+x?[x.pop()+(0|x.shift()),...f(x)]:[]
```
[Try it online!](https://tio.run/##dcxLCsIwEADQfU8xC6EJjoN/xZJ6kBhoqI2m1CS0tQTUs0dw7/rBa/Wkh7q3YVw4f21SMiKKMs7jWUYKPjA@Z8t3pOFuzcg4RyIyLHJ1kioVk@7BuvAcQYDMAOQKYY2wQdgi7BD2CAeEo8I/pjJVZLV3g@8a6vyN/TJ66MA0iBKq2cswzT8Vp9Zbx/KLyzkv0hc "JavaScript (Node.js) ‚Äì Try It Online")
[Answer]
# [R](https://www.r-project.org/), ~~81~~ ~~70~~ ~~68~~ 57 bytes
```
function(l)c((l+rev(l))[1:(w=sum(l|1)/2)],l[w+1][!!w%%1])
```
[Try it online!](https://tio.run/##K/qfZvs/rTQvuSQzP08jRzNZQyNHuyi1DMjUjDa00ii3LS7N1cipMdTUN9KM1cmJLtc2jI1WVCxXVTWM1fyfpmFoZaLJBaJMIZQZhDKHUBaa/wE "R ‚Äì Try It Online")
anonymous function; returns the result.
[Answer]
# [Zsh](https://www.zsh.org/), 55 bytes
If the answer must be put to stdout, but output whitespace is flexible, **55 bytes**:
```
for ((;++i<=#/2;))<<<$[$@[i]+$@[-i]]
<<<$@[#%2*(1+#/2)]
```
[Try it online!](https://tio.run/##XYzLCoMwEEX38xWXaEEbQmuq1mIE/0OyEIwYEAXti/58mnTZuxhmzhnuZ5/cbu4Qb3pNdjbYTD9gtoupMaxknv2MnxdgccDMjeuGJKk5t6qJTrJOU6VU3MVtZzX3U1itKaC2iw7ymGTcf6XaPZZQZINiTQijYV2MyyBxQY4CJa6o6O/GjUQGUfm9gCi9OFMuib4 "Zsh ‚Äì Try It Online")
---
If the output must be stored in an array, **53 bytes**: (We can't use this method in place of the above because of `<<<...[--i]...`. The here-string forces a subshell, so the decremented value of `i` never makes it out.)
```
for n ($@[1,#/2])y+=($[$@[--i]+n])
y+=$@[#%2*(1+#/2)]
```
[Try it online!](https://tio.run/##XYzLCoMwFET39yuGmILWhjapWksV@h@ShWCKAYmgfdmfT2OXvas5Z4b7mXs/mzvEm169HQwm03YYrDMXdCOZZzvg1wswvmrmb@MEh5hfG7mL9konS1rHvAkshNWp0wkFEzDaqG0s07BJtK@qii/0cOszB4uFgmH1eoy60RkvoXBEhhwFTijpj3EmISHKkHOIIhQHyhTRFw "Zsh ‚Äì Try It Online")
If the answer must be output in one line separated by spaces, then append `<<<$y` for a 6 byte penalty.
---
Zsh arrays are indexed from the start starting at `1`, or from the end starting at `-1`. So what happens if you attempt to index at `0`? Well, nothing! We take advantage of that here to only output the middle number based on a parity check:
```
$@[#%2*(1+#/2)]
   #      #       # parameter count
       (1+#/2)    # index of the middle element when count is odd
   #%2*(1+#/2)    # multiply by 0 if even, or 1 if odd
$@[           ]   # Index the parameter array
```
[Answer]
# [Factor](https://factorcode.org/), 35 bytes
```
[ halves reverse 0 pad-longest v+ ]
```
[Try it online!](https://tio.run/##ZY29DgFBFEZ7T/H1YuOf0OhEoxGVKMb62I0xu@69JkT22QeVQndycpJzcrlVkrab1Xo5g/J2Z8ipP8r4MHGKq7Mii/zWigsl0KMWmj1rKYNh3mq90EMfAwwxwhgTTNH8uSbtUDgfPwthpCjRRe2OHV@FM9UQ29inQ7lApsg9naQ3 "Factor ‚Äì Try It Online")
## Explanation
It's a quotation (anonymous function) that takes a sequence from the data stack and leaves a sequence on the data stack. Assuming `{ 1 2 3 4 5 6 7 }` is on the data stack when this quotation is called...
| Snippet | Comment | Data stack (top on right) |
| --- | --- | --- |
| `halves` | Split a sequence in half | `{ 1 2 3 } { 4 5 6 7 }` |
| `reverse` | Reverse a sequence | `{ 1 2 3 } { 7 6 5 4 }` |
| `0 pad-longest` | Pad the shorter of two sequences with 0s until it's the same length as the longer sequence | `{ 1 2 3 0 } { 7 6 5 4 }` |
| `v+` | Vector addition; element-wise addition between two sequences | `{ 8 8 8 4 }` |
 
[Answer]
# [Go](https://go.dev), 115 bytes
```
func(x[]int)(o[]int){s:=len(x)
for i:=range x[:s/2]{o=append(o,x[i]+x[s-i-1])}
if s%2>0{o=append(o,x[s/2])}
return}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=dU5LasMwFNzrFGogIBE5bdz8MKhnyN54IWLJiMZPRpKDwOgW3WVjCj1UblM7zqKBZjW8mTefy3dl-utLI46fopK4FhqQrhtj_XKmaj9D6CwsVvyn9SrZX51q4UhCXmjwlJgJO5fxkwQSKFLGYp1xK2AIC3nmXtOiM1w0jYSSGBZyXSxC7hKdrAoakVbYzdOPt8ef0TWIVvrWQrxXf43Vt4GE4g7JswSccXyb0K1Yyt7Zmm3Ylu3YPiJTlk_UiA52IE9AFBlDKP1DDLaHe_Jv4j_kyN239f2Evw)
### Generic with custom operator, 136 bytes
```
func f[T any](x[]T,O func(T,T)T)(o[]T){s:=len(x)
for i:=range x[:s/2]{o=append(o,O(x[i],x[s-i-1]))}
if s%2>0{o=append(o,x[s/2])}
return}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=fVHNTgMhGIxXnoJsYgIpVVutNmvWV6iHvW2IYf8qdgsrbO2aDXffwUtj4sVH8E30aQTpxmoaD4TJDN8wMM8vc7l5r1m2YPMCLhkXgC9rqZqjoFw2AXhdNeVw-vFUrkQGyySGTDxS1CY0JjPoSBSTGMcYSUvhTodRVQjUYlBKBXkYKSasb5uE-nhMOxmxui5EjiSZWRNOSZvoIR-OKMYG8BLqw_HVye4xq9tBK6qiWSlhfJ7Pg7fvQC4vwrADLM9hGPlAjKSQiwbb1fkpyAapAcVDIdyhhDplRMbklJyRCTknF2RqgPQWe1QDrpUlK4HKxO4UOSdir8T4r2JN9gvedmL-U3sR6EZpn8UiLuZdcFtUlQwIDNZSVbkD9yueLRxIlVwLB0rZBgbUSt4VWcOl-PUh3sjW1KPOFXRDVF8R2xK6J9LO9qGiSHdyEPkhpLAx5hJuu9h5hdcpcskJ_MlgX7OtbLPx-xc)
[Answer]
# [Curry (PAKCS)](https://www.informatik.uni-kiel.de/%7Epakcs/index.html), 34 bytes
```
f(a:b++[c])=a+c:f b
f x@([]?[_])=x
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m706ubSoqDK-IDE7uXjBgqWlJWm6FjeV0jQSrZK0taOTYzVtE7WTrdIUkrjSFCocNKJj7aPjgYIVEJW7chMz8xRsFdIUog11jHSMdUx0THXMdMx1LGIhCmBGAgA)
Based on the sample implementation in Haskell.
[Answer]
# C (gcc), ~~62 bytes~~ 60 bytes
-2 bytes thanks to [@ceilingcat](https://codegolf.stackexchange.com/users/52904/ceilingcat)
```
i;f(v,l)int*v;{for(i=0;i<l/2;++i)v[i]+=v[l+~i];return~l/-2;}
```
`f` is a function taking vector (`v`) and length (`l`) as arguments. It modifies the vector and returns the new length.
[Try It Online!](https://tio.run/##VY9hi4MwDIY/N78iDAbtWdEJd18yf4nIOJzdBXp1ONfBxP11r9UxdvkSwvs8CWnSU9PMM5ORXlvFbvjwNJqul1zmxHubFZQkrHzFdVL6yiYPrqlvh2vvHjZLC5oAgoW/3@yk7/ioYAR8VgwsX4aqxhLHT41fGguNu1xjutMYWjERiAVr3Wn4CZi88L3tzOIpzP7NVV4rglVw7e3wkoyMsX5uCYwIL6CMHIc4p9D2bwphfApHEOLcB8rIzfaIG71e4XhFTDDBPP8B)
How it works:
```
i;
f(v,l) int*v; // v is an integer pointer (or array), l is an integer
{
    for (i = 0; i < l / 2; ++i) // iterate through half the indices using i (if l is odd, the middle element won't be included)
        v[i] += v[l + ~i]; // add the value at the i'th index from the back to the i'th index from the front. ~i == -i - 1, so l + ~i == l + -i -1 = l - i - 1 (l - 1 is the first index from the back, and we subtract i for each index beyond the first)
    return ~l / -2; // return half the length rounded up (~l == -l - 1 => ~l / -2 == (-l - 1) / -2 => (l + 1) / 2
}
```
[Answer]
# [BQN](https://mlochbaum.github.io/BQN/), ~~15~~ 12 bytes
```
(‚åä‚â†√∑2Àô)‚ä∏‚Üë‚ä¢+‚åΩ
```
[Try it online!](https://bqnpad.mechanize.systems/s?bqn=eyJkb2MiOiJpbnB1dCDihpAg4p%2BoMSwgMiwgMywgNCwgNSwgNSwgNiwgNywgOOKfqVxuU29sIOKGkCAo4oyK4omgw7cyy5kp4oq44oaR4oiYKOKKoivijL0pXG5Tb2wgaW5wdXQiLCJwcmV2U2Vzc2lvbnMiOltdLCJjdXJyZW50U2Vzc2lvbiI6eyJjZWxscyI6W10sImNyZWF0ZWRBdCI6MTY3NDI0MDM3ODA1OX0sImN1cnJlbnRDZWxsIjp7ImZyb20iOjAsInRvIjo2NywicmVzdWx0IjpudWxsfX0%3D)
-3 thanks to Marshall Lochbaum
Sum the list and its reverse, then take the first `‚åä‚â†√∑2Àô` digits. `‚åä‚â†√∑2Àô` the floor of the length divide 2. Floor is necessary because there is no integer division in BQN. `‚ä∏` is used to bind the output of `‚åä‚â†√∑2Àô` to the take operator `‚Üë` on the left and also puts the output of `(‚ä¢+‚åΩ)` on the right. Better explanation [here](https://mlochbaum.github.io/BQN/tutorial/combinator.html#before-and-after).
[Answer]
# [Nibbles](http://golfscript.com/nibbles/index.html), 6.5 bytes
```
/`\~_!:\@0@+
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m708LzMpKSe1eMGCpaUlaboWa_QTYuriFa1iHAwctCFCUJkFN60MFYwUjBVMFEwVzBTMFSy4UPhcILYpUNzQUMHQWMEQyLBUMDJWMLJUMDaEGAEA)
```
/   Fold
`\~  split into two parts
_     input (row from STDIN as a list of integers)
!    zip
:     join
\      reverse
@       the second part
0      0
@     the first part
+     with addition
```
[Answer]
# [Julia 1.0](http://julialang.org/), ~~69~~ 68 bytes
```
!s=(~=length;~s%2>0&&insert!(s,(1+~s)√∑2,0);(s+reverse(s))[1:~s√∑2])
```
[Try it online!](https://tio.run/##yyrNyUw0rPj/X7HYVqPONic1L70kw7quWNXIzkBNLTOvOLWoRFGjWEfDULuuWPPwdiMdA01rjWLtotSy1KLiVI1iTc1oQ6u6YqBMrOZ/h8RikAYFxWhDHSMdYx0THVMdMx1zHYtYBVtbhWhLHTCM5cKhDqLKQgcETWL/AwA "Julia 1.0 ‚Äì Try It Online")
-1 byte thanks to MarcMush: replace `==1` with `>0`
[Answer]
# [Nekomata](https://github.com/AlephAlpha/Nekomata), 6 bytes
```
;·∂ú√ß‚Üî·∂ª+
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70iLzU7PzexJHFZtJJurlLsgqWlJWm6FmutH26bc3j5o7YpD7ft1l5SnJRcDJVZcFMx2lDHSMdYx0THVMdMx1zHIpYLVSQWohIA)
```
;·∂ú√ß‚Üî·∂ª+
;       Nondeterministically split the input into two parts
 ·∂ú√ß     Optionally prepend a zero to the second part
   ‚Üî    Reverse the second part
    ·∂ª+  Zip with addition
```
The `+` operator is automatically vectorized, but it does not check if the two operands have the same length. So here I use `·∂ª` (`\zip`) to make sure that the two parts are of equal length.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 35 bytes
```
Set[f[a_,b___,c_],a+c,f@b]
f@a___=a
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78/z84tSQ6LToxXicpPj5eJzk@VidRO1knzSEplivNIREoZpv4P6AoM68kWlnXLs3BQTlWrS44OTGvrporKDEvPdXBXAfKsOCq/Q8A "Wolfram Language (Mathematica) ‚Äì Try It Online")
Input `[list...]`. Returns a sequence.
---
## [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 39 bytes
```
f@{a_,b___,c_}:={a+c,##&@@f@{b}}
f@a_=a
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78/z/NoToxXicpPj5eJzm@1sq2OlE7WUdZWc3BASiTVFvLleaQGG@b@D@gKDOvJFpZ1y7NQTlWrS44OTGvrporKDEvPdXBXAfKsOCq/Q8A "Wolfram Language (Mathematica) ‚Äì Try It Online")
Input and output a list instead of a sequence.
[Answer]
# [Perl 5](https://www.perl.org/) `-aE`, 36 bytes
```
map{$F[$_]+=pop@F}0..$#F/2-1;say"@F"
```
Takes advantage of the autosplit flag and iterates through the first half (rounded down) of the resulting list, modifying it in-place.
Slightly ungolfed:
```
for (0 .. ($#F / 2) - 1) {
    $F[$_] += pop(@F);
}
say "@F";
```
[Try it online!](https://tio.run/##K0gtyjH9/z83saBaxS1aJT5W27Ygv8DBrdZAT09F2U3fSNfQujixUsnBTen/f0MjYy5DBSMFKKlgomCKYCmYcRkaKBgAuQYKhgb/8gtKMvPziv/rJiro@prqGRgaAAA "Perl 5 ‚Äì Try It Online")
[Answer]
# [sed](https://www.gnu.org/software/sed/) `-E`, 60 bytes
```
s/^/</
:a
s/<(!*);(.*;)?(!*);$/\1\3,<\2/
ta
s/[<;]//g
s/,$//
```
Only works with zero and positive numbers.
Input is repeated exclamation marks separated by semicolons.
Output is repeated exclamation marks separated by commas.
[Try it online!](https://tio.run/##K05N0U3PK/3/v1g/Tt9Gn8sqkatY30ZDUUvTWkNPy1rTHsxU0Y8xjDHWsYkx0ucqAamItrGO1ddPB7J0VPT1//9XtFYEITCGEFASRsFpRWsuIhT/yy8oyczPK/6v6woA "sed ‚Äì Try It Online")
[Answer]
# [Uiua](https://www.uiua.org/), 12 bytes
```
‚¨ö0+‚áå‚äÉ‚Üò‚Üô‚åä√∑2‚ßª.
```
[Try it online!](https://www.uiua.org/pad?src=ZiDihpAg4qyaMCvih4ziioPihpjihpnijIrDtzLip7suCmYgWzEgMiAzIDQgNSA2IDcgOCA5XQpmIFsxIDIgMyA0IDUgNiA3IDhd)
```
‚¨ö0+‚áå‚äÉ‚Üò‚Üô‚åä√∑2‚ßª.   input: a numeric vector
           ‚åä√∑2‚ßª     half of length, rounded down (let's call it k)
     ‚äÉ‚Üò‚Üô     .   fork(drop, take): first k elements removed, first k elements
   ‚áå               reverse the top
‚¨ö0+                elementwise add, filling with zeros when lengths don't match
```
]