| Bytes | Lang | Time | Link |
|---|---|---|---|
| 035 | Tcl | 250515T213832Z | sergiol |
| 028 | Zsh & coreutils | 250516T224830Z | roblogic |
| 011 | TIBASIC TI83 Plus | 250515T132430Z | madeforl |
| 024 | C# | 250515T145232Z | Ezlandin |
| 003 | jq | 231230T010846Z | manatwor |
| 035 | Gema | 231229T235149Z | manatwor |
| 087 | Swift | 231229T170049Z | Annett S |
| 001 | Regex | 231227T135112Z | emanresu |
| 050 | Desmos | 230504T003324Z | Jakdad J |
| 039 | minigolf | 230504T034405Z | user1176 |
| 003 | Python | 200322T224106Z | Jonathan |
| 6261 | Python 3 | 230428T140425Z | Hunaphu |
| 000 | Thunno 2 S | 230427T180346Z | The Thon |
| 023 | ><> Fish | 230426T064846Z | mousetai |
| 1267 | Mornington Crescent | 200501T052850Z | Cloudy7 |
| 2910 | Rust | 230424T115653Z | JSorngar |
| 019 | Scala | 230424T102658Z | 138 Aspe |
| 056 | Java JDK | 230424T100442Z | Fhuvi |
| 057 | Lua | 230424T014503Z | bluswimm |
| 021 | MAWP 1.1 | 200917T083022Z | lyxal |
| 004 | Pip | 200917T070555Z | Razetime |
| 537 | Mornington Crescent | 200916T134135Z | Dorian |
| 066 | Rockstar | 200916T143351Z | Shaggy |
| 059 | SNOBOL4 CSNOBOL4 | 200619T200553Z | Giuseppe |
| 143 | Brainetry | 200617T232739Z | RGS |
| 075 | C++ clang | 200617T201905Z | anatolyg |
| 021 | SQL | 200422T142258Z | StRaWbEr |
| 009 | PHP | 200324T113153Z | Kaddath |
| 008 | x8616 machine code | 200420T213248Z | 640KB |
| 087 | Python 2 | 200322T223753Z | Surculos |
| 035 | Java 8 | 200420T142944Z | Muskovet |
| 006 | Burlesque | 200420T100708Z | Mintable |
| 040 | Javascript | 200420T053445Z | Steve Be |
| 003 | Haskell | 200420T032129Z | MLavrent |
| 110 | C++ gcc | 200419T090341Z | Stealing |
| 002 | Pushy | 200419T103255Z | FlipTack |
| 004 | J | 200419T062304Z | PkmnQ |
| 093 | Batch | 200418T032455Z | ScriptKi |
| 018 | Ruby | 200401T193809Z | G B |
| 015 | Java | 200325T231240Z | Tony Bas |
| 003 | Haskell | 200325T142812Z | Benji |
| 001 | Pyth | 200323T085700Z | Mukundan |
| 057 | Bash + GNU utilities | 200322T235402Z | Mitchell |
| 038 | C gcc | 200322T235001Z | dingledo |
| 003 | Charcoal | 200323T211448Z | Neil |
| 079 | Retina 0.8.2 | 200323T211048Z | Neil |
| 6024 | PowerShell | 200323T102828Z | wasif |
| 018 | perl ple | 200323T140115Z | StRaWbEr |
| 133 | Racket | 200323T135628Z | Galen Iv |
| 004 | Red | 200323T131006Z | Galen Iv |
| 001 | 05AB1E | 200323T082931Z | Kevin Cr |
| 001 | W | 200323T015254Z | user9206 |
| 002 | Keg | 200322T234627Z | lyxal |
| 141 | GERMAN | 200322T231807Z | Jonathan |
| 094 | C gcc | 200322T225514Z | S.S. Ann |
| 003 | Python 2/Python 3 | 200322T222657Z | RGS |
| 021 | JavaScript ES6 | 200322T220849Z | Arnauld |
| 001 | Japt | 200322T222157Z | Shaggy |
| 001 | Jelly | 200322T221509Z | Jonathan |
| 002 | APL dzaima/APL | 200322T215857Z | Adá |
| 002 | Wolfram Language Mathematica | 200322T221015Z | ZaMoC |
Tcl, 35 bytes
Command line arguments approach.
lmap x {*}$argv {incr t $x}
puts $t
Tcl, 38 bytes
Function approach.
proc S L {lmap x $L {incr t $x}
set t}
Zsh & coreutils, 30 28 bytes
eval echo ${(j:$'\53':)@}|bc
$'\53' evaluates to + (octal 53 in Ascii).
Original, 30 bytes: S=0;for i;S=$S$'\53'$i;bc<<<$S
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
jq, 3 characters
add
Takes the input as array.
Sample run:
bash-5.2$ jq 'add' <<< '[-64, -64, 16]'
-112
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
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.
Python, 3 bytes
sum
Built in function which does the job
With no built-in, 36 bytes in Python 2:
-3 thanks to ovs!
lambda a:eval(`a`.replace(*',\x2b'))
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).
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
><> (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/
><> (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$/
Mornington Crescent, 1267 bytes
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>()
Depending on how the rules should be interpreted it could be possible to solve it using only 10 bytes:
|n|n.sum()
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.
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();}
Pip, 4 bytes
_MSg
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
// 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
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.
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
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:])
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
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;}
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#
As you can probably guess, S sums all values on the stack and # outputs this as a number.
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.
Java, 15 bytes
Math.addExact()
You give it your two variables as parameters
Haskell, 3 Bytes
sum
calculates the sum of a list
Bash + GNU utilities, 57 bytes
printf %.f $(bc -l<<<"99*l(e(`sed 's@ @/99)*e(@g'`/99))")
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.
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.
perl -ple, 18 bytes
s/ /\x2b/g;$_=eval
Reads a space separated list of numbers from STDIN, writes the sum to STDOUT.
perl -MList::Util=sum -alpe, 8 bytes
$_=sum@F
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))))))
Well...
05AB1E, 1 bytes
O
Input as a list.
Try it online or verify all test cases.
Slightly less boring:
1β
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
÷⅀
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.
JavaScript (ES6), 21 bytes
Takes input as an array of integers.
a=>eval(a.join`\x2B`)
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)
Jelly, 1 byte
S
A built-in monadic atom which given a list yields the sum.
No built-in, 2 bytes:
ḅ1
Converts from base one to an integer.
APL (dzaima/APL), 2 bytesSBCS
Anonymous tacit prefix function
1⊥
Simply evaluates a "digit" list in base 1.

