g | x | w | all
Bytes Lang Time Link
034Swift 6250429T181221ZmacOSist
019Raku Perl 6 rakudo250423T154817Zxrs
018TIBASIC TI83250331T161843Zabsolute
048Tcl170725T115649Zsergiol
003Uiua231013T175118Zchunes
002Thunno 2230611T135533ZThe Thon
014Juby221120T204436ZJordan
006K ngn/k220507T044540Zoeuf
022Desmos220507T034621ZAiden Ch
007Risky220129T064419ZDyad Han
4439tinylisp220202T194922Zchunes
002Vyxal220112T093905Zchunes
019HP 48 User REPL220104T014002ZTheSlive
008Add++220102T002441Zlyxal
021Juby220102T063534ZRazetime
004Pip p220102T040912ZDLosc
018Factor211231T054844Zchunes
005K4 / K oK180503T195639Zmkst
005Stax180503T160107Zwastl
025CasioBasic171010T074237Znumberma
028ARBLE171010T223038ZATaco
0228th170821T170406ZChaos Ma
005MY170726T182003ZAdalynn
053Java 8170816T074218ZKevin Cr
057C# .NET Core170724T184001Zjkelm
nanPerl 5170816T031811ZXcali
004Husk170815T225312Zბიმო
057C++14170806T110501ZKarl Nap
017Clojure170725T104053Zcliffroo
030Swift 3170726T164957ZAlexande
058Swift170724T183257ZMr. Xcod
021Clojure170726T061950Zdmh
019R170726T052429ZXingzhou
027JavaScript ES6170724T190347ZNeil
049Scala170725T144811ZTamoghna
016R170724T182338ZGiuseppe
032PowerShell170724T182013ZAdmBorkB
014Pari/GP170725T124820Zalephalp
060C# .NET Core170724T213127ZGrzegorz
033Common Lisp170725T112726Zuser6516
019x86 Machine Code 32bit protected mode170725T095555ZCody Gra
059PHP170725T005518ZTitus
002Jelly170724T181634Zhyperneu
003MATL170724T221323ZDJMcMayh
005J170724T214556ZRichard
033JavaScript ES6170724T182156ZRick Hit
032Python 2170724T201307Zovs
012Mathematica170724T183337ZZaMoC
031Retina170724T200010ZNeil
022Röda170724T185936Zuser4180
049C170724T193059Zorlp
007Stacked170724T190756ZConor O&
032Python 2170724T181802Zvaultah
002Neim170724T190100ZOkx
003J170724T185740ZJonah
030Racket170724T185040ZBusiness
031Python 2 + numpy170724T184625Zwnnmaw
026PowerShell170724T184806ZJoey
025Ruby170724T184117ZVentero
007Japt170724T183255ZJustin M
003APL Dyalog170724T182634Zuser4180
003anyfix170724T183149Zhyperneu
004Actually170724T183139ZErik the
015Perl 6170724T183106ZSean
031Ruby 2.4170724T182812ZValue In
006Brachylog170724T182558ZErik the
059Positron170724T182435Zhyperneu
040Python 2170724T181725Ztotallyh
007CJam170724T182254ZErik the
003Ohm170724T182213Ztotallyh
020Haskell170724T181902ZWheat Wi
005Pyth170724T181919ZMr. Xcod
003Pyth170724T181851ZErik the
00205AB1E170724T181716ZErik the

Swift 6, 34 bytes

{zip($0+[0],$0.reversed()).map(+)}

Try it on SwiftFiddle!

Raku (Perl 6) (rakudo), 22 19 bytes

{@^a Z+@^a.reverse}

Attempt This Online!

TI-BASIC (TI-83), 18 bytes

Ans+seq(Ans(X),X,dim(Ans),1,⁻1

A simple program that adds the list in Ans with a sequence that reverses it.

The language does not support empty lists, but the other test cases are successful.


Note: TI-BASIC is a tokenized language. Character count does not equal byte count.

Program size is equal to \$MEM\: byte\: count - program\: name\: length - 9\: bytes\$.

Tcl, 48 bytes

proc R L {lmap l $L r [lreverse $L] {incr l $r}}

Try it online!

Uiua, 3 bytes

+⇌.

Try it!

+⇌.
  .  # duplicate
 ⇌   # reverse
+    # add

Thunno 2, 2 bytes

r+

Attempt This Online!

r is reverse and + is add.

J-uby, 14 bytes

:zip%:~|:*&+:+

Attempt This Online!

:zip % :~ |           # Zip array with its reverse, then
            :* & +:+  # Map with sum

K (ngn/k), 6 bytes

{x+|x}

Try it online!

Desmos, 22 bytes

f(l)=l+l[l.length...1]

Pretty self-explanatory

Try It On Desmos!

Try It On Desmos! - Prettified

Risky, 7 bytes

0__2-?_+_?+_0

Try it online!

Appends -? (first input reversed) to __ (all inputs, which is in this case a trick to wrap the input array), and then transposes. Maps with sum, which is the most complicated usage of Risky's quicks that I'm even going to attempt.

tinylisp, 44 39 bytes

(load library
(q((p)(map* a p(reverse p

-5 bytes thanks to @DLosc

Try it online!

Explanation

An anonymous function that maps the a function (addition) over pairwise elements in the input and the reverse of the input, forming a new list.

Vyxal, 2 bytes

Ḃ+

Try it Online!

Ḃ+
Ḃ  # bifurcate, i.e. duplicate and reverse
 + # vectorized addition of two lists

HP 48 User REPL, 19 bytes

« DUP REVLIST +
»

Explanation

« and » mark the object as a program.

DUP - Duplicates the list

REVLIST - Reverses the list

+ - Sums them

Add++, 8 bytes

L,dbRz£+

Try it online!

Finally something sane with Add++

Explained

L,dbRz£+
L,        ; create a lambda that:
  dbR     ; pushes the input list and its reverse
     z    ; zips those together
      £+  ; and reduces each pair by addition

J-uby, 21 bytes

:zip%:reverse|:*&:sum

Try it online!

Pip -p, 4 bytes

g+Rg

Attempt This Online!

Explanation

Just what it says on the tin.

   g  List of command-line arguments
  R   Reversed
g+    Add to the original list

(Addition operates element-wise on lists in Pip.)

Factor, 18 bytes

[ dup reverse v+ ]

Try it online!

Explanation

         ! { 1 2 3 }
dup      ! { 1 2 3 } { 1 2 3 }
reverse  ! { 1 2 3 } { 3 2 1 }
v+       ! { 4 4 4 }

K4 / K (oK), 5 bytes

Solution:

x+|x:

Try it online!

Example:

x+|x:,()
,()
x+|x:8 92
100 100
x+|x:,999
,1998

Explanation:

Not quite as elegant as the J solution, but same kinda thing:

x+|x: / the solution
   x: / store input as x
  |   / reverse it
 +    / add to
x     / x

Stax, 5 bytes

òôΩo1

Run and debug it

I like that sequence of o-style chars (òôΩo).

Explanation (unpacked):

cr\m|+ Full program, implicit input  e.g.: [1, 2, 3]
cr     Copy and reverse                    [1, 2, 3] [3, 2, 1]
  \    Zip                                 [[1, 3], [2, 2], [3, 1]]
   m|+ Map sum of array                    [4, 4, 4]
       Implicit output

Casio-Basic, 25 bytes

l+seq(l[x],x,dim(l),1,-1

Addition threads over lists by default - but there's no built-in for reversing a list! seq is used to generate the reversed list by indexing backwards through it.

24 bytes for the function, +1 byte to add l in the parameters box.

ARBLE, 28 bytes

map(a,a+index(c,len(c)-b+1))

Try it online!

8th, 22 bytes

Code

clone a:rev ' n:+ a:op

SED (Stack Effect Diagram) is: a -- a

Ungolfed code with comments

: f \ a -- a 
  clone      \ clone array on TOS 
  a:rev      \ reverse array 
  ' n:+ a:op \ Add the corresponding elements of each array producing a new array
;

Usage

ok> [8,92] clone a:rev ' n:+ a:op .
[100,100]

Test cases

ok> [8,92] f .
[100,100]
ok> [1,2,3] f .
[4,4,4]
ok> [5,24,85,6] f .
[11,109,109,11]
ok> [] f .
[]
ok> [999] f .
[1998]

MY, 49 48 5 bytes

ωω⌽+←

Try it online!

How?

First, you bang your head against the wall after remembering that addition on strings isn't commutative. Then, you bang your head yet again after realizing that you could've used ω to save over 40 bytes! Finally, you arrive at this:

ω    - First command line argument
ω⌽   - First command line argument, reversed
+    - Add (vectorizes)
←    - Output without a newline

Java 8, 61 57 56 53 bytes

a->{for(int l=0,r=a.length;l<r;a[l]=a[--r]+=a[l++]);}

-1 byte and bug-fixed thanks to @Nevay.
-3 bytes thanks to @OliverGrégoire.

(It was a port of (and golfed by 4 8 bytes) of @jkelm's C# answer, but now it's a different shorter solution thanks to @OliverGrégoire.)

Explanation:

Try it here.

The method modifies the input-array to save bytes, so no need for a return-type.

a->{                    // Method with integer-array parameter and no return-type
  for(int l=0,          //  Left-integer (starting at 0)
          r=a.length;   //  Right-integer (starting at the length of the input-array)
      l<r;              //  Loop as long as left is smaller than right
    a[l]=               //   Change the number at the current left index to:
         a[--r]+=a[l++] //    The number at the right index + itself
                        //    (The += adds the number at the left index also to the right index)
                        //    (And the --/++ increases/decreases the indexes by 1,
                        //     until we've reached the middle of the array)
  );                    //  End of loop
}                       // End of method

C# (.NET Core),65 57 bytes

-8 bytes thanks to Kevin Cruijssen

n=>{for(int i=0,o=n.Length;i<o/2;)n[i]=n[o-1-i]+=n[i++];}

Try it online!

Perl 5, 24 + 1 (-a) = 25 bytes

print$_+$F[--$i],$"for@F

Try it online!

Husk, 4 bytes

Sz+↔

Try it online! (Note if you want to test with empty list, you need to supply: []:LN as argument)

Ungolfed/Explanation

      -- implicit input list        - [1,2,3]
S     -- "duplicate input and"      - [1,2,3] [1,2,3]
   ↔  -- reverse one copy           - [1,2,3] [3,2,1]
 z+   -- zip with original using +  - [1+3,2+2,3+1]

C++14, 57 bytes

As generic unnamed lambda requiring a container and returns via modifying its input:

[](auto&L){auto R=L;auto r=R.end();for(auto&x:L)x+=*--r;}

Try it online!

Ungolfed:

[](auto&L){
 auto R=L;      //copy of the list
 auto r=R.end();//iterator of last+1
 for(auto&x:L)  //foreach
  x+=*--r;      //move iterator to front and sum
}

Clojure, 20 17 bytes

3 bytes saved thanks to @MattPutnam

#(map +(rseq %)%)

Seems to be quite competitive with non-golfing languages.

See it online

Swift 3, 30 bytes

{zip($0,$0.reversed()).map(+)}

Swift, 76 68 58 bytes (returns an Array)

-8 bytes thanks to @Alexander.

func f(l:[Int]){print(zip(l,l.reversed()).map(+))}

Try it online!


Swift, 76 66 bytes

func f(l:[Int]){for i in 0..<l.count{print(l.reversed()[i]+l[i])}}

Try it online!

Prints the sums separated by a newline. For [1,2,3], the output is:

4
4
4

Clojure, 21 bytes

#(map + %(reverse %))

Try it online!

Having trouble golfing this any further. Any clever ideas?

R: 19 bytes

function(v)rev(v)+v

Try It Out: http://www.r-fiddle.org/#/fiddle?id=vJhwqK77

JavaScript (ES6), 27 bytes

a=>[...a].map(e=>e+a.pop())

f=
a=>[...a].map(e=>e+a.pop())

console.log(f([8, 92])) // [100, 100]
console.log(f([1, 2, 3])) // [4, 4, 4]
console.log(f([5, 24, 85, 6])) // [11, 109, 109, 11]
console.log(f([])) // []
console.log(f([999])) //[1998]

Scala, 49 bytes

(a:Seq[Int])=>a.zip(a.reverse)map{case(a,b)=>a+b}

Lambda. Paste in the REPL, it gets assigned to a default variable, like res0 or whatever. Note the variable name from the output produced after pasting that line into the REPL and pressing Enter, let's say it's res4. To call the lambda, just use res4(Seq(1, 2, 3)) or res4(Seq(89, 88, 1, 2, 3, 1000, 2000)) for the test cases.

Implementation notes:

zip creates a Tuple2 from 2 Seqs, which need to be unpacked in the pattern match (the case expression after the map) before the elements can be added. Indexed access is convoluted for golfing in Scala...

Here's another version, using convoluted indexing tricks for 57 bytes:

(a:Seq[Int])=>{val l=a.size-1;0.to(l)map(i=>a(i)+a(l-i))}

This just produces a new Seq from adding the "complementary" elements of the Seqs (symmetrically about the mid of the Seq. Very imperative.

I don't like it either, but the type ascriptions are necessary to get the REPL to accept it, otherwise it just botches out Missing Parameter Type.

The idea in the 2nd version can be used in Java 8 as well, just swapping in IntStream.rangeClosed(0,l) instead of Scala's implicit to on Ints, unlike the former, which would be considerably more convoluted in Java.

Note that @jkelm's answer for C# can be trivially translated to Java.

R, 17 16 bytes

-1 byte thanks to djhurio

rev(l<-scan())+l

Reads from stdin; returns the vector; numeric(0) is the zero-length numeric vector for the empty list.

Try it online!

PowerShell, 40 32 bytes

($n=$args)|%{$n[-++$i]+$n[$i-1]}

Try it online!

Takes input as individual command-line arguments, which is allowed as one of the native list format for PowerShell. Then loops through each element (i.e., a shorter way of looping through the indices), adding the element counting from the back (-1 indexed) to the current element (0 indexed, hence the decrement -1). Those are left on the pipeline and output is implicit.

Saved 8 bytes thanks to @briantist

Pari/GP, 14 bytes

a->a+Vecrev(a)

Try it online!

C# (.NET Core), 61 60 bytes

-1 byte thanks to TheLethalCoder

a=>a.Reverse().Zip(a,(x,y)=>x+y).ToArray()

Try it online!

Byte count also includes:

using System.Linq;

For explanation - Zip function in LINQ takes two collections and executes given function for all corresponding elements, ie. both first elements together, both second elements etc.

Common Lisp, SBCL, 33 bytes

Pretty simple solution (very similiar to Clojure one):

(lambda(x)(mapcar'+(reverse x)x))

Example of use:

((lambda(x)(mapcar'+(reverse x)x))'(1 2 3)))

Try it online!(with print function, to show output from function)

x86 Machine Code (32-bit protected mode), 19 bytes

8D 34 B7 39 F7 73 0C 83 EE 04 8B 07 03 06 89 06 AB EB F0 C3

The above bytes of code define a function that takes two parameters (a pointer to the array in the EDI register, and the length of the array in the ESI register), modifies the pointed-to array to contain the "reverse array sum", and then returns. It does not return a value to the caller.

(This is a custom calling convention used to receive the arguments. It is actually the standard calling convention used on Gnu/Unix systems for x86-64 binaries, but in x86-32, arguments are typically passed on the stack. That takes more bytes to encode, and is less efficient, so we want to ensure that the arguments are passed to us in registers. As far as I understand the rules, this is completely legal. We don't need to conform to a particular standardized calling convention. Certainly, when writing assembly, the programmer is free to define her own calling conventions, unless she needs to interoperate with C code.)

Note that this function also assumes the direction flag is cleared (DF == 0) upon entry to the function. This is a sensible assumption, as it is guaranteed by most platform ABIs, including the Linux x86 32-bit ABI. If you need the code to work under circumstances where the state of DF cannot be assumed, then you need to add a 1-byte CLD instruction to the top of the function.

Ungolfed assembly mnemonics:

               ; void ReverseArraySum(int *pArray, int length);
8D 34 B7         lea    esi, [edi+esi*4]        ; compute back pointer
               Loop:
39 F7            cmp    edi, esi
73 0C            jae    End                     ; finished when EDI >= ESI
83 EE 04         sub    esi, 4
8B 07            mov    eax, DWORD PTR [edi]
03 06            add    eax, DWORD PTR [esi]
89 06            mov    DWORD PTR [esi], eax
AB               stosd  ; equivalent to 'mov DWORD PTR es:[edi], eax' + 'add edi, 4'
EB F0            jmp    Loop
               End:
C3               ret

Conceptually, the code is pretty straightforward. We just iterate through the array using two pointers. The first pointer is passed to us as an argument, in the register EDI, and it is a pointer to the beginning of the array. The second pointer is computed (initial LEA instruction) by adding the address of the beginning of the array to the length of the array, scaled by the size of an element in the array (4 bytes for an int on x86-32). Thus, ESI is a pointer to the end of the array.

At the top of the Loop, we check the pointers to see if we should keep looping or if we are finished. Normally, we'd want to save bytes by putting this test at the end of the loop (and eliminating the JMP you see at the end now), but we can't do that because the challenge requires us to handle an empty input array.

Inside the body of the loop, we:

Finally, we're done and we return to the caller, without returning any value.

__
You can see it run on TIO, but note that the TIO link uses a C wrapper to exercise the machine code, and GCC won't necessarily respect our custom calling convention, so we have to add extra code at the top of the function to retrieve the parameters from the stack and put them into the appropriate registers.

PHP, 59 bytes

for(;a&$c=$argv[++$i];)$a[]=$c+$argv[$argc-$i];print_r($a);

takes input from command line arguments; empty output for empty input

Yields a warning in PHP>7.0. This version does not (60 bytes):

for(;++$i<$argc;)$a[]=$argv[$i]+$argv[$argc-$i];print_r($a);

Jelly, 2 bytes

+U

Try it online!

or

+Ṛ

Try it online! (thanks @Mr. Xcoder for the second program)

explanation, though it's pretty self-explanatory

+U  Main link
+   Add, vectorizing, 
 U                    the input, reversed

+Ṛ  Main link
+   Add, vectorizing,
 Ṛ                    the input, reversed, without vectorizing (same thing for depth-1 lists)

For empty array [], this outputs nothing. That is correct. Jelly's representation of an empty list is just simply nothing. Note that Jelly's representation of a list with a single element is just the element itself. Append ŒṘ to the code to see the Python internal representation of the output.

MATL, 3 bytes

tP+

Try it online!

Extremely straightforward. t duplicates the input. P flips (reverses) it, and + adds the two arrays element wise.

J, 5 bytes

(+|.)

    (+|.) 1 2 3    ===> 4 4 4
    (+|.) 89 98 1 2 3 1000 2000  =====> 2089 1098 4 4 4 1098 2089

    NB. Does not work without the parentheses as per previous answer by @Jonah

JavaScript (ES6), 34 33 bytes

Saved a byte thanks to @ETHproductions.

a=>a.map((e,i)=>e+a[a.length+~i])

let f=

a=>a.map((e,i)=>e+a[a.length+~i])

console.log(f([8,92]));
console.log(f([1,2,3]));
console.log(f([5, 24, 85, 6]));
console.log(f([]));
console.log(f([999]));

Python 2, 33 32 bytes

-1 byte thanks to @xnor

lambda l:[i+l.pop()for i in l*1]

Try it online!

Mathematica, 12 bytes

Reverse@#+#&

Try it online!

Retina, 31 bytes

\d+
$*1;$&$*
O$^`;1+

;

1+
$.&

Try it online! Explanation:

\d+
$*1;$&$*

Convert to unary and duplicate each element.

O$^`;1+

Reverse the order of the duplicate elements.

;

Add the elements to their reversed duplicates.

1+
$.&

Convert the elements back to decimal.

Röda, 22 bytes

{reverse(_)<>_1|[_+_]}

Try it online!

This is an anonymous function that takes in an array and returns a stream of values, which the TIO link outputs separated over newlines.

Explanation

reverse(_)          The array reversed
<>                  interleaved with
_1                  the array itself
                    Push each element to the stream
[_+_]               Pull two values and push their sum

C, 49 bytes

f(a,n,b)int*a,*b;{for(b=a+n;a<b--;a++)*a=*b+=*a;}

Stacked, 7 bytes

[:rev+]

Try it online!

Just adding to the reversed.

Python 2, 32 bytes

lambda l:map(sum,zip(l,l[::-1]))

Alternative solution without zip (35 bytes):

lambda l:map(int.__add__,l,l[::-1])

Try it online!

Neim, 2 bytes

This is a function that takes input on the top of the stack and outputs on the top of the stack.

𝕓𝔻

Try it online!

J, 3 bytes

+|.

Reverse, sum.

Try it online!

Racket, 30 bytes

(lambda(l)(map +(reverse l)l))

Try it online!

This is simply an anonymous function that maps corresponding elements from l and l reversed to the + function, returning the results in a list.

Python 2 + numpy, 31 bytes

I think this is kosher based on the rules, but let me know if not.

Anonymous function takes a numpy array as input:

import numpy
lambda l:l+l[::-1]

Try it online!

PowerShell, 26 bytes

($a=$args)|%{+$a[--$i]+$_}

Try it online!

Takes input as command-line arguments.

Ruby, 25 bytes

->a{[*a].map{|i|i+a.pop}}

Try it online!

Japt, 7 bytes

mÈ+Ug~Y

Try it online! with the -Q flag to format the output array.

Explanation

Implicit: U = input array

Map the input by the following function...

+Ug

The value, plus the value in the input array at index...

~Y

-(index+1), which gets elements from the end of the array.

APL (Dyalog), 3 bytes

⌽+⊢

Try it online!

Explanation

⌽          The argument reversed
+           Plus
⊢          The argument

anyfix, 3 bytes

"U+

The version on TryItOnline! is an outdated version of anyfix, which contains a few fatal errors such as not being able to add lists because of typos in the source code. Use the code on GitHub instead.

"U+  Program
"    Duplicate top of stack
 U   Reverse top of stack if it is a list (which it should be...)
  +  Add, vectorizing for lists

Actually, 4 bytes

;R♀+

Try it online!

Perl 6, 15 bytes

{$_ Z+.reverse}

Try it online!

Ruby 2.4, 31 bytes

Hooray, TIO supports Ruby 2.4 now!

->a{a.zip(a.reverse).map &:sum}

Try it online!

Brachylog, 6 bytes

↔;?z+ᵐ

Try it online!

Positron, 59 bytes

->{a=[]i=0;while(i<len@$1)do{a+=[$1@i+($1@(-(i+1)))]i++};a}

Try it online!

This has many golfing opportunities that have been ruined by Positron's brokenness :P

Python 2, 40 bytes

lambda l:[i+j for i,j in zip(l,l[::-1])]

Try it online!

The other, shorter Python answer replaces a list comprehension with map. Wish I'd thought to do that faster. ;-;

CJam, 7 bytes

{_W%.+}

Try it online!

Ohm, 3 bytes

DR+

Try it online!

Haskell, 20 bytes

5 bytes save by changing to a point free as suggested by nimi

zipWith(+)=<<reverse

Try it online!

Pyth, 5 bytes

sMC_B

Try it online!

Pyth, 3 bytes

+V_

Try it here.

05AB1E, 2 bytes

Â+

Try it online!