g | x | w | all
Bytes Lang Time Link
035Tcl250515T213832Zsergiol
028Zsh & coreutils250516T224830Zroblogic
011TIBASIC TI83 Plus250515T132430Zmadeforl
024C#250515T145232ZEzlandin
003jq231230T010846Zmanatwor
035Gema231229T235149Zmanatwor
087Swift231229T170049ZAnnett S
001Regex231227T135112Zemanresu
050Desmos230504T003324ZJakdad J
039minigolf230504T034405Zuser1176
003Python200322T224106ZJonathan
6261Python 3230428T140425ZHunaphu
000Thunno 2 S230427T180346ZThe Thon
023><> Fish230426T064846Zmousetai
1267Mornington Crescent200501T052850ZCloudy7
2910Rust230424T115653ZJSorngar
019Scala230424T102658Z138 Aspe
056Java JDK230424T100442ZFhuvi
057Lua230424T014503Zbluswimm
021MAWP 1.1200917T083022Zlyxal
004Pip200917T070555ZRazetime
537Mornington Crescent200916T134135ZDorian
066Rockstar200916T143351ZShaggy
059SNOBOL4 CSNOBOL4200619T200553ZGiuseppe
143Brainetry200617T232739ZRGS
075C++ clang200617T201905Zanatolyg
021SQL200422T142258ZStRaWbEr
009PHP200324T113153ZKaddath
008x8616 machine code200420T213248Z640KB
087Python 2200322T223753ZSurculos
035Java 8200420T142944ZMuskovet
006Burlesque200420T100708ZMintable
040Javascript200420T053445ZSteve Be
003Haskell200420T032129ZMLavrent
110C++ gcc200419T090341ZStealing
002Pushy200419T103255ZFlipTack
004J200419T062304ZPkmnQ
093Batch200418T032455ZScriptKi
018Ruby200401T193809ZG B
015Java200325T231240ZTony Bas
003Haskell200325T142812ZBenji
001Pyth200323T085700ZMukundan
057Bash + GNU utilities200322T235402ZMitchell
038C gcc200322T235001Zdingledo
003Charcoal200323T211448ZNeil
079Retina 0.8.2200323T211048ZNeil
6024PowerShell200323T102828Zwasif
018perl ple200323T140115ZStRaWbEr
133Racket200323T135628ZGalen Iv
004Red200323T131006ZGalen Iv
00105AB1E200323T082931ZKevin Cr
001W200323T015254Zuser9206
002Keg200322T234627Zlyxal
141GERMAN200322T231807ZJonathan
094C gcc200322T225514ZS.S. Ann
003Python 2/Python 3200322T222657ZRGS
021JavaScript ES6200322T220849ZArnauld
001Japt200322T222157ZShaggy
001Jelly200322T221509ZJonathan
002APL dzaima/APL200322T215857ZAdá
002Wolfram Language Mathematica200322T221015ZZaMoC

Tcl, 35 bytes

Command line arguments approach.

lmap x {*}$argv {incr t $x}
puts $t

Try it online!


Tcl, 38 bytes

Function approach.

proc S L {lmap x $L {incr t $x}
set t}

Try it online!

Zsh & coreutils, 30 28 bytes

eval echo ${(j:$'\53':)@}|bc

Try it online!

$'\53' evaluates to + (octal 53 in Ascii).


Original, 30 bytes: S=0;for i;S=$S$'\53'$i;bc<<<$S

Try it online!

TI-BASIC (TI-83 Plus), 19 11 bytes

Input L₁
sum(ΔList(cumSum(L₁

it doesn't need the first element so it cuts it out

C#, 24 bytes

int F(int[] l)=>l.Sum();

Try it online!

jq, 3 characters

add

Takes the input as array.

Sample run:

bash-5.2$ jq 'add' <<< '[-64, -64, 16]'
-112

Try it online! / Try all test cases online!

Gema, 35 characters

<N>=@set{s;@add{${s;};$0}}
?=
\Z=$s

Takes an input string with anything separated numbers.

Sample run:

bash-5.2$ gema '<N>=@set{s;@add{${s;};$0}};?=;\Z=$s' <<< '-64, -64, 16'
-112

Try it online! / Try all test cases online!

Swift, 87 bytes

The xor & carry based approach. The return type of a function in Swift is defined using the arrow like f() -> Int with a "minus" character, so my function needs to print the value and not return it :-) (that way actually 5 bytes shorter than returning the result)

func s(_ a:[Int]){var r=0;for var c in a{while 0 != c{(r,c)=(r^c,(r&c)<<1)}};print(r)}

Regex, 1 byte

x

Try it online! Takes input as space-delimited unary, outputs using the number of matches. This is a standard I/O format for regex that just happens to trivialise this challenge.

Desmos, 50 bytes

\sum_{n=1}^{a.\operatorname{length}}a\left[n\right]

Takes input as array a

View it on Desmos

minigolf, 39 bytes

1i,ny*_:1<sv,1s/_:,:ny=!ns,,___s,_s,T*_

Attempt This Online!

Python, 3 bytes

sum

Built in function which does the job

Try it online


With no built-in, 36 bytes in Python 2:

-3 thanks to ovs!

lambda a:eval(`a`.replace(*',\x2b'))

Try it online!

Note: a single value may be represented as a singleton list (meta)

Python 3, 62/61 bytes

Without relying on sum in other functions.

def f(i,x=0):
	for y in i:
		while y:x,y=x^y,(x&y)*2
	return x

Can be shortened to 61 by removing the function definition (-13), replacing in i: with in eval(input()): (+12) and print instead of return at the end (+0).

Try it online!

Thunno 2 S, 0 bytes

That's right. No bytes. The S flag takes the sum.

Thunno 2, 1 byte

S

1 byte flagless. Built-in for sum.

Screenshots

Screenshot 1 Screenshot 2

><> (Fish), 23 bytes

Takes input in unary, separated by NULL bytes. A bit cheaty, let me know if you think this is valid or no.

i:0=?~:0(?v
       ;nl/

Try it

><> (Fish), 34 bytes

Input must be length prefixed. Uses p to modify the source code at runtime to insert + and - instructions.

'V'2,61p0iv
:?!v$i $1 >59*91p
;n$/

Try it

Mornington Crescent, 1267 bytes

Try it online!

Poorly golfed, may have to have another attempt tomorrow.

Take Northern Line to Bank
Take Northern Line to Euston
Take Victoria Line to Seven Sisters
Take Victoria Line to Victoria
Take Circle Line to Victoria
Take Circle Line to Bank
Take District Line to Parsons Green
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Parsons Green
Take District Line to Parsons Green
Take District Line to Upminster
Take District Line to Upney
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Parsons Green
Take District Line to Bank
Take Circle Line to Moorgate
Take Circle Line to Temple
Take Circle Line to Moorgate
Take Circle Line to Bank
Take District Line to Parsons Green
Take District Line to Upney
Take District Line to Upminster
Take District Line to Upney
Take District Line to Upminster
Take District Line to Upney
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Parsons Green
Take District Line to Bank
Take Circle Line to Moorgate
Take Circle Line to Hammersmith
Take Circle Line to Embankment
Take Northern Line to Charing Cross
Take Northern Line to Angel
Take Northern Line to Bank
Take District Line to Upney
Take District Line to Bank
Take Circle Line to Bank
Take Northern Line to Mornington Crescent

Rust, 29 (maybe 10?) bytes

Since Rust supports signed integers natively we have to use a signed type, but the challenge lets us choose the type beyond that, so I choose i8 in order to save two bytes.

|n:&[i8]|n.iter().sum::<i8>()

Attempt This Online!

Depending on how the rules should be interpreted it could be possible to solve it using only 10 bytes:

|n|n.sum()

Attempt This Online!

by moving the type declarations into the driving code, but that requires the driving code to contain the - character, which I feel is against the rules.

Scala, 19 bytes

Try it online!

def f(a:Int*)=a.sum

Java (JDK), 56 bytes

For once, in this challenge we can't use Java lambdas because its arrow -> contains the - sign!

So i think the shortest way in Java to add N numbers
(unlike using a pre-built function that only adds 2 numbers, which has also been explicitly disallowed by OP)
without using + and -, is this approach:

int f(int...a){return java.util.Arrays.stream(a).sum();}

Try it online!

Lua, 57 bytes

print(load("return "..table.concat(arg,('').char(43)))())

Try it online!

MAWP 1.1, 21 bytes

%@[~@~1A]_1A[%M_1A]%:

Try it!

Input taken as:

number_of_inputs
n1
n2
n3
...
nN

Pip, 4 bytes

_MSg

Try it online!

MS maps a function to an iterable and sums its results.

_ is the identity function.

g is the list of command line args.

Mornington Crescent, 634 537 bytes

Take Northern Line to Bank
Take District Line to Parsons Green
Take District Line to Upminster
Take District Line to Temple
Take District Line to Hammersmith
Take District Line to Parsons Green
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Parsons Green
Take District Line to Bank
Take Northern Line to Charing Cross
Take Northern Line to Angel
Take Northern Line to Bank
Take District Line to Upminster
Take District Line to Bank
Take Circle Line to Bank
Take Northern Line to Mornington Crescent

Try it online!

// initialize adder
Take Northern Line to Bank          // save input to Hammersmith
Take District Line to Parsons Green // get 0
Take District Line to Upminster     // set Upminster = 0

// set start of loop
Take District Line to Temple

// extract leading number
Take District Line to Hammersmith
Take District Line to Parsons Green

// add it to previous sum
Take District Line to Upminster     // accumulator = sum
                                    // Upminster = previous accumulator

// save sum in Upminster
Take District Line to Upminster

// get remaining string
Take District Line to Parsons Green

// check if it is equal to "" by translating the first char to its codepoint (0 if empty)
// we ride a few extra rounds here, adding 0s to the sum
Take District Line to Bank          // save string and 
                                    // get string of previous round
Take Northern Line to Charing Cross // swap accumulator with Charing Cross
                                    // and get codepoint of previous values' 
                                    // first char (that's from two rounds ago)
                                    // or 0 if empty

// if string is not empty (meaning, accumulator is non-zero), repeat
Take Northern Line to Angel

// else read sum
Take Northern Line to Bank          // get empty string
Take District Line to Upminster     // swap with Upminster

// and go home, outputting the number
Take District Line to Bank          // change lines, swapping data with Bank
Take Circle Line to Bank            // swap back
Take Northern Line to Mornington Crescent // go home

Rockstar, 66 bytes

listen to N
R's0
while N
cast N
let R be with N
listen to N

say R

Try it here (Code will need to be pasted in, with each input integer on an individual line)

SNOBOL4 (CSNOBOL4), 59 bytes

N S =S ' ' CHAR(43) ' ' INPUT :S(N)
O OUTPUT =EVAL(0 S)
END

Try it online!

Brainetry, 143 bytes

a b c d e f
a b
a b c d e f
a b c d e f g h
a b c d e f g h
a b c d e

a b c d
a
a b c d e f g h i
a b c d e f
a b c d e f g h i

a b c d e f g

To try it online follow this repl.it link and paste the code in the btry/replit.btry file, then press the green "Run" button. Does I/O as ASCII codepoints.

The program above is the golfed version of this program:

Let me sum some numbers carefully.
Carefully enough
so that I do not use
the plus or minus signs, that'd be awful.
After I do this, oh so very carefully,
I just have to ...
Move the pointer
left and right for
a while.
This is the main gist of the whole program.
Of course this sounds somewhat uninteresting.
That is because you, my dear reader, lack depth.
(Is it "depth"?
Maybe that's not the correct English word...)

C++ (clang), 81 75 bytes

[](auto x){decltype(x)r;for(int a:x)r.insert(r.end(),a,0);return r.size();}

I used a generic lambda to avoid the need for #include.

It uses a temporary container, to which it appends lists of zeros of needed lengths. The output is the length of the resulting list.

Thanks to S.S. Anne for the idea of using decltype! I used auto earlier, and it was worse because I had to clear the list before working with it.

Try it online!

SQL, 21 bytes

SELECT SUM(N) FROM T;

This assumes the numbers to be in table T, in a column named N.

PHP, 20 9 bytes

array_sum

Try it online!

still wondering if this is not too easy here.. EDIT: thanks to @640KB for saving 11 bytes!

x86-16 machine code, 8 bytes

33 D2       XOR  DX, DX         ; clear running sum (in DX)
        AN: 
AD          LODSW               ; load next value into AX
03 D0       ADD  DX, AX         ; add AX to running sum
E2 FB       LOOP AN             ; loop until CX = 0
C3          RET                 ; return to caller

Input size in CX, data in [SI]. Output sum in DX.

Python 2, 97 95 93 88 87 bytes

Solution that doesn't use the built-in sum, eval or exec:

-2 bytes thanks to @JonathanAllan!
-1 byte thanks to @ovs!

x=y=1
for i in input():x<<=i*(i>0);y<<=abs(i)
y/=x
print" ~"[x<y],len(bin(x/y|y/x)[3:])

Try it online!

Input: a comma separated list of numbers, from stdin.
Output: the sum is printed to stdout. If the sum is negative, the ~ sign is used instead of - due to source code restriction.

How: Let \$p\$ be the sum of all positive numbers in the list, and \$n\$ be the magnitude of the sum of all negative numbers. Then the sum of the list is \$p-n\$.

Let \$x=2^p\$ and \$y=2^n\$, then \$\frac xy=2^{p-n}\$.

Thus if the sum is positive (aka \$x>y\$), we can calculate the sum by counting the number of zeros in the binary representation of \$\frac xy\$. Otherwise, we can calculate the magnitude of the sum as the number of zeros in the binary representation of \$\frac yx\$.

Java 8, 35 bytes

x->x.stream().mapToInt(x->x).sum()

Takes a List of Integers.

Burlesque, 6 bytes

ps{}ms

Try it online!

Takes input as a space separated string from stdin. Explanation:

ps      # Parse input as block
    ms  # Map and sum result
  {}    # Empty mapping function

Javascript (40 characters)

x=>eval(x.join(String.fromCharCode(43)))

The boring and obvious way to do this, I guess.

Javascript (48 characters)

x=>x.reduce((a,v)=>[...a,...Array(v)],[]).length

A bit lame, but my first attempt. Concatenates arrays of the length of each number, then finds the total length of that array.

Haskell, 3 bytes

sum

Function that takes an argument as a list e.g. sum[1,2,3] and returns the sum of the list.

C++ (gcc), 83, 110 bytes

#include <iostream>
int n,x,c;int f(int i){while(i){c=n&i;n^=i;i=c<<1;}if(std::cin>>x)f(x);else std::cout<<n;}

Try it online!

Explanation: Reads in integer inputs and preforms bit-wise addition.

I tried to simplify the carry step like this but it gave me a negative result.

Pushy, 2 bytes

S#

Try it online!

As you can probably guess, S sums all values on the stack and # outputs this as a number.

J, 4 bytes

1&#.

This was literally taken from here.

Batch, 93 bytes

43 is the ASCII code for +:

@!! 2>nul||cmd/q/v/c%0&&exit/b
set c=cmd/c
set/pn=
%c%exit 43
%c%set/a !n: =%=exitcodeascii%!

Takes input via STDIN, delimited by space.

Ruby, 18 bytes

def f(*a)a.sum end

Try it online!

Java, 15 bytes

Math.addExact()

You give it your two variables as parameters

Haskell, 3 Bytes

sum

calculates the sum of a list

Pyth, 1 byte

s

Try it online!

Explanation

s(Q)
 (Q) : Implicit evaluated input
s    : Sum the input

Bash + GNU utilities, 57 bytes

printf %.f $(bc -l<<<"99*l(e(`sed 's@ @/99)*e(@g'`/99))")

Try it online!

Reads space-separated integers from stdin, and writes the output to stdout.

This applies the exponential function to each integer, multiplies the results, and then takes the natural logarithm of the product. I need to scale the input numbers (and then "unscale" the result) so as not to overflow the exponentials on some of the starred test examples (that's what the 99* and /99 are doing there).

C (gcc), 50 45 43 38 bytes

f(s,e)char**s;{s=s<e?&f(&s[1])[*s]:0;}

-7 bytes thanks to @S.S. Anne
-5 bytes thanks to @Bubbler

Takes for input start and end pointers. It uses the fact that the address of &a[b] equals a+b. Other than that, even I am a bit confused as to how this works.

Try it online!

Charcoal, 3 bytes

IΣA

Try it online! Link is to verbose version of code. Explanation:

  A Input as an array
 Σ  Take the sum
I   Cast to string
    Implicitly print

Retina 0.8.2, 79 bytes

O`[^,\d]?\d\d*
\d\d*
$*
,[^,1]

^([^,1]1*),
$1;
,

\D?(1*);\1

^(\D)?(1*)
$1$.2

Try it online! Link includes test cases. Explanation:

O`[^,\d]?\d\d*

Sort the numbers.

\d\d*
$*

Convert the numbers to unary.

,[^,1]

Total the numbers that are less than zero.

^([^,1]1*),
$1;

Separate the numbers that are less than zero from those that are not less than zero.

,

Total the numbers that are not less than zero.

\D?(1*);\1

Add the less than zero total to the not less than zero total.

^(\D)?(1*)
$1$.2

Convert to decimal.

Adding nonnegative integers is much easier of course.

\d\d*
$*
1

Try it online! Explanation: Each integer is converted into unary and then the total is converted into decimal.

PowerShell, 60 24 bytes

$args-join[char]0x2b|iex

Try it online!

-36 bytes thanks to @mazzy

perl -ple, 18 bytes

s/ /\x2b/g;$_=eval

Try it online!

Reads a space separated list of numbers from STDIN, writes the sum to STDOUT.

perl -MList::Util=sum -alpe, 8 bytes

$_=sum@F

Try it online!

Racket, 133 bytes

(define(f a[s 0])(if(null? a)s(let([c(car a)])(if(= 0 c)(f(cdr a)s)(f(cons((if(> 0 c)add1 sub1)c)(cdr a))((if(> 0 c)sub1 add1)s))))))

Try it online!

Well...

Red, 4 bytes

:sum

Try it online!

Takes the input as a block (list)

05AB1E, 1 bytes

O

Input as a list.

Try it online or verify all test cases.

Slightly less boring:

Try it online or verify all test cases.

Explanation:

O   # Sum the (implicit) input-list
    # (and output the result implicitly)

1β  # Convert the (implicit) input-list to base-1
    # (and output the result implicitly)

W, 1 bytes

Takes input as a list and... just a summation function... :-)

J

W j, 0 bytes

Haha, even more cheaty! The j flag automatically evaluates the J command at the end of the source code.


Keg, -hr, 2 bytes

÷⅀

Try it online!

The joys of not having implemented lists properly! Simply item split and summate. Essentially uses a sum function, so no imaginary points for me.

GERMAN, 141 bytes

EINGABESCHLEIFENANFANGSUBTRAKTIONRECHTSEINGABESCHLEIFENANFANGSUBTRAKTIONRECHTSADDITIONLINKSSCHLEIFENENDELINKSSCHLEIFENENDERECHTSRECHTSAUSGABE

C (gcc), 94 bytes

x,c;n(a,b){for(;b;b=x*2)x=a&b,a^=b;x=a;}f(a,t)int*a;{for(c=1;c<t;c=n(c,1))*a=n(*a,a[c]);c=*a;}

A non-trivial golfed reference implementation.

I realized I had worded myself out of an answer when I couldn't even use + or - for a counter variable.

Try it online!

Python 2/Python 3, 3 bytes

sum

Try it online (Py 3)! or Try it online (Py 2)!

JavaScript (ES6), 21 bytes

Takes input as an array of integers.

a=>eval(a.join`\x2B`)

Try it online!


JavaScript (ES6), 40 bytes

Takes input as an array of integers.

a=>a.reduce(g=(x,y)=>y?g(x^y,(x&y)*2):x)

Try it online!

Japt, 1 byte

Trivial challenges get trivial solutions!

x

Try it

Jelly, 1 byte

S

A built-in monadic atom which given a list yields the sum.

Try it online!


No built-in, 2 bytes:

ḅ1

Converts from base one to an integer.

Try it online!

APL (dzaima/APL), 2 bytesSBCS

Anonymous tacit prefix function

1⊥

Try it online!

Simply evaluates a "digit" list in base 1.

Wolfram Language (Mathematica), 2 bytes

Tr finds the trace of the matrix or tensor list

Tr

Try it online!