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 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