71
\$\begingroup\$

Input: Two integers. Preferably decimal integers, but other forms of numbers can be used. These can be given to the code in standard input, as arguments to the program or function, or as a list.

Output: Their sum. Use the same format for output integers as input integers. For example, the input 5 16 would lead to the output 21.

Restrictions: No standard loopholes please. This is , answer in lowest amount of bytes wins.

Notes: This should be fairly trivial, however I'm interested to see how it can be implemented. The answer can be a complete program or a function, but please identify which one it is.

Test cases:

1 2 -> 3
14 15 -> 29
7 9 -> 16
-1 8 -> 7
8 -9 -> -1
-8 -9 -> -17

Or as CSV:

a,b,c
1,2,3
14,15,29
7,9,16
-1,8,7
8,-9,-1
-8,-9,-17

Leaderboard

var QUESTION_ID=84260,OVERRIDE_USER=8478;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

asked Jul 2, 2016 at 0:40
\$\endgroup\$
3
  • 31
    \$\begingroup\$ This is quite trivial, but not really simpler than, e.g., the Hello World catalog. Given that the ability to add integers is one of our two requirements for programming languages, I'd say it's worthwhile to have if properly specified. \$\endgroup\$ Commented Jul 2, 2016 at 0:48
  • 2
    \$\begingroup\$ Can the answer take input with preceding zeros as default? e.g. 5 16 is inputted as 005 016 \$\endgroup\$ Commented Dec 4, 2016 at 11:56
  • 1
    \$\begingroup\$ @FinW Sure. As long as they don't get interpreted as octal. \$\endgroup\$ Commented Dec 4, 2016 at 20:47

243 Answers 243

1 2
3
4 5
...
9
3
\$\begingroup\$

Befunge, 5 bytes

&&+.@

  • & takes an integer as input and puts it on the stack
  • + pops two numbers from the stack and puts the sum back on the stack
  • . pops a number from the stack and outputs it as an integer
  • @ ends the program

Try it: http://www.quirkster.com/iano/js/befunge.html

answered Jul 4, 2016 at 6:54
\$\endgroup\$
3
\$\begingroup\$

Nim, 3 bytes

`+`

In Nim, the functions behind operators are specified by surrounding them in backticks. This is then the function behind the addition operator, which adds its two parameters.

Use like this:

echo `+`(1, 1)

To test:

$ echo "echo \`+\`(1, 1)" > sum.nim
$ nim c sum.nim
$ ./sum
2
answered Aug 27, 2016 at 12:08
\$\endgroup\$
3
\$\begingroup\$

Perl 6, 3 bytes

*+*

A lambda that takes two arguments and returns their sum.

answered Aug 27, 2016 at 13:05
\$\endgroup\$
3
\$\begingroup\$

C, 19 bytes

f(a,b){return a+b;}
answered Oct 9, 2016 at 10:00
\$\endgroup\$
3
  • \$\begingroup\$ 17 bytes: f(a,b){b+=a;a=b;} \$\endgroup\$ Commented Dec 7, 2017 at 14:55
  • 1
    \$\begingroup\$ @JohanduToit In C language, in how it is defined as language you have to use return if the function has to return its result. If one compiler put in eax or rax that result : It is too much fragile (possible change some optimization flag, or change the compiler or the Os or the Pc etc: and the result will be different) \$\endgroup\$ Commented Dec 7, 2017 at 18:40
  • \$\begingroup\$ @JohanduToit: This is a C answer, not an "x86 gcc -O0" answer (or whatever you're programming for), so you can't use some silly hack that happens to generate machine code leaving a value in eax. \$\endgroup\$ Commented Dec 17, 2017 at 19:29
3
\$\begingroup\$

SQL, 141 Bytes

Just for fun...

Golfed:

CREATE PROCEDURE S @a INT,@b INT AS BEGIN DELETE FROM ABC INSERT INTO ABC(A)VALUES(@a)INSERT INTO ABC(A)VALUES(@b)SELECT SUM(A)FROM ABC END
GO

Ungolfed:

CREATE PROCEDURE S
@a INT,
@b INT 
AS 
BEGIN 
DELETE FROM ABC 
INSERT INTO ABC(A)
VALUES(@a)
INSERT INTO ABC(A)
VALUES(@b)
SELECT SUM(A)FROM ABC END
GO

Requires a 1 column table creating:

CREATE TABLE ABC
(
A INT,
);

Then call the stored procedure like this:

EXEC S 4, 9
--13
answered Oct 27, 2016 at 17:17
\$\endgroup\$
3
\$\begingroup\$

Japt, 1 byte

x

Here is a non-1 byte solution

U+V

Try it online!

answered Jan 9, 2017 at 15:47
\$\endgroup\$
2
  • 1
    \$\begingroup\$ I read that as × at first and got really confused :P \$\endgroup\$ Commented Jan 10, 2017 at 20:07
  • \$\begingroup\$ @ETHproductions Ha! It threw me off when you first added ×. I was wondering why it only worked when I copy-pasted it from the docs -- I was typing x :P \$\endgroup\$ Commented Jan 10, 2017 at 20:20
3
\$\begingroup\$

Bubblegum, 98 bytes

00000000: 6672 6f6d 206d 6174 6820 696d 706f 7274 from math import
00000010: 2066 6163 746f 7269 616c 2061 7320 4623 factorial as F#
00000020: 0a74 7279 3a6e 3d69 6e74 2869 292d 313b .try:n=int(i)-1;
00000030: 6f3d 6e2a 2846 286e 2925 2d7e 6e3d 3d6e o=n*(F(n)%-~n==n
00000040: 290a 6578 6365 7074 3a6f 3d73 756d 286d ).except:o=sum(m
00000050: 6170 2869 6e74 2c69 2e73 706c 6974 2829 ap(int,i.split()
00000060: 2929 ))

Try it online! (Note that the online interpreter takes input in xxd format)

Bubblegum is really good at three things:

  1. Compressing large outputs,

  2. Testing for primality, and

  3. Adding a sequence of numbers.

It's really really really bad at everything else.

answered Jan 11, 2017 at 7:49
\$\endgroup\$
3
\$\begingroup\$

Alice, (削除) 7 (削除ここまで) 6 bytes

Thanks to Sp3000 for saving 1 byte.

+/
o@i

Try it online!

Explanation

Someone say again that golfing addition in languages that have an addition built-in is trivial...

A quick primer on Alice:

  • Alice has two modes: if the instruction pointer moves orthogonally, Alice is in Cardinal mode and can perform operations on integers. If the instruction pointer moves diagonally, Alice is in Ordinal mode and can perform operations on strings.
  • Data type conversion happens automatically when a value of the wrong type is popped from the stack.
  • Mirrors (\ and /) reflect the path of the IP through 67.5 degrees and switch between Cardinal and Ordinal mode. Here is a diagram of every possible reflection.
  • In Cardinal mode, if the IP hits the boundary of the grid it wraps around, as it does in many other 2D languages. If in Ordinal mode, the IP is reflected off the boundary instead.

The instruction pointer bounces all over the place in this solution:

+ Adds two implicit zeros on the stack, but effectively does nothing.
/ Send the IP southeast. Switch to Ordinal mode.
i Read all input as a single string.
 We're in Ordinal mode, so the IP bounces off the corner of the grid
 and moves back northwest.
/ Send the IP west. Switch to Cardinal mode.
 We're in Cardinal mode, so the IP wraps to the end of the first line.
+ Try to add two numbers. The top of the stack is a string though, so Alice
 implicitly replaces it with the integers contained in the string, and
 then adds those two numbers.
/ Send the IP northwest. Switch to Ordinal mode.
 We're in Ordinal mode, so the IP immediately bounces off the top boundary
 and moves southwest instead.
o Print a string to STDOUT. Since the top of the stack is a number, that
 number is first implicitly converted to its decimal string representation.
 We're in Ordinal mode, so the IP bounces off the corner of the grid
 and moves back northwest.
/ Send the IP south. Switch to Cardinal mode.
@ Terminate the program.
answered Apr 11, 2017 at 11:26
\$\endgroup\$
3
\$\begingroup\$

Lost, 9 bytes

v<<<
>%+@

Try it online!

Explanation

This is about as simple as lost programs get. Since the start location and direction are random we need to have a stream around the edges to catch the ip we then direct it into the %+@ which will perform the addition.

Alternative version

////
\%+@

Try it online!

answered Aug 6, 2017 at 0:52
\$\endgroup\$
6
  • \$\begingroup\$ So the IP can spawn at any random position on the top row and left column of the playing field? \$\endgroup\$ Commented Sep 26, 2017 at 4:08
  • \$\begingroup\$ @MDXF The ip can spawn anywhere including the top row and left column. \$\endgroup\$ Commented Sep 26, 2017 at 4:15
  • \$\begingroup\$ So what happens if the location starts on @? \$\endgroup\$ Commented Oct 31, 2017 at 21:48
  • \$\begingroup\$ @cairdcoinheringaahing It depends on the direction, but you can follow it out for yourself, the only one that takes a bit is the one traveling left, which goes all the way to the mirror before getting bounced back. Remember that in Lost % needs to be encountered before the program can exit on a @. \$\endgroup\$ Commented Oct 31, 2017 at 22:52
  • \$\begingroup\$ @WheatWizard Ah, didn't know about the % rule. Interesting language! \$\endgroup\$ Commented Oct 31, 2017 at 23:11
3
\$\begingroup\$

INTERCAL, 74 bytes

DO WRITE IN .1
DO WRITE IN .2
DO (1000) NEXT
PLEASE READ OUT .3
DO GIVE UP

Try it online!

INTERCAL is so user-friendly that even something so simple as adding requires a call to the system library in DO (1000) NEXT. I'm working on a more complete answer using only INTERCAL's, uh, "unique", built-in operators.

PLEASE NOTE for those trying this program: INTERCAL takes input in numbers with each digit as an English (or Sanskrit, Basque, Tagalog, Classical Nahuatl, Georgian, or Kwakiutl) word, separated by spaces, so ONE ONE inputs 11, DALAWA LIMA inputs 25, and ZAZPI BAT BI inputs 712. A newline separates different inputs, and because of how the parser works, there must be a trailing space at the end of the last input. Numbers are output as Roman Numerals.

answered Sep 27, 2017 at 14:15
\$\endgroup\$
1
  • \$\begingroup\$ 57 bytes \$\endgroup\$ Commented Sep 15, 2021 at 3:52
3
\$\begingroup\$

AWK - 11 bytes

The code:

{0ドル=1ドル+2ドル}1

Can run as:

awk '{0ドル=1ドル+2ドル}1' <<< "98.342 77.123"

Could also store the code in a file sum.awk and run as:

awk -f sum.awk <<< "98.342 77.123"

If you wanted a program that wouldn't require knowing that you were using awk, you could create a file sum that looks like:

#!/bin/awk -f
{0ドル=1ドル+2ドル}1

Assuming of course that the awk executable is located at /bin/awk. If this file is made executable, it could simply be run as:

 sum <<< "98.342 77.123"

or

echo "98.342 77.123" | sum

Or place the numbers in a file, DATA, and run as:

sum DATA

A tiny bit of explanation. 0ドル represents a single line of input that is also automatically split into numbered fields. This line is then overwritten by the assignment. The lone 1 acts as a label that always evaluates to true and its default action is to simply print the current 0ドル.

answered Jul 28, 2016 at 12:57
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Wouldn't you still have to run it as sum <<< "98.342 77.123", or echo | sum? \$\endgroup\$ Commented Dec 17, 2017 at 19:46
  • \$\begingroup\$ You are correct. It would work better if the data were placed in a file, or as you suggested. \$\endgroup\$ Commented Dec 20, 2017 at 19:56
  • 1
    \$\begingroup\$ What I came up with is so similar, I'll post it a suggestion change... You can use 1,0ドル=1ドル+2ドル to do the same thing in one less character. \$\endgroup\$ Commented May 8, 2021 at 1:07
3
\$\begingroup\$

Java, (削除) 11 (削除ここまで) (削除) 10 (削除ここまで) 9 bytes

a->b->a+b 

Ungolfed test code

public static void main(String[] args) {
 Function<Integer, Function<Integer, Integer>> func = (a -> b -> a + b);
 System.out.println(func.apply(5).apply(10));
}
answered Oct 6, 2016 at 8:25
\$\endgroup\$
2
  • \$\begingroup\$ You can save 1 byte: a->b->a+b; \$\endgroup\$ Commented Oct 8, 2016 at 11:09
  • \$\begingroup\$ The count is 9 bytes, not 10 bytes. The final semicolon is not to be counted because it's not part of the lambda expression. For example: one could pass the lambda as someLambdaAcceptingMethod(a->b->a+b). \$\endgroup\$ Commented Jun 3, 2018 at 7:41
3
\$\begingroup\$

Bit, 985 bytes (non-competing)

I spent 2 hours on this, I present to you, an answer in Bit.

Behavior is undefined if one of the input numbers OR the sum of them is >= 10000, each of the 4 digits should be written aka 5 -> 0005, STDIN is read 2 times to get the 2 numbers.

Done without using extra files (that's an achievement for Bit programs, because no extra files means no if statements)

BIT 1
BYTE 1
BIT 0
BIT 1
BYTE 2
BIT 1
BIT 1
BYTE 3
BIT 0
BIT 1
BIT 0
BIT 1
BYTE a
BYTE b
BYTE c
BIT 0
BIT 0
BIT 0
BIT 0
BIT 1
BIT 1
BYTE d
BYTES 1 e
POWER a 2 b
POWER a 3 c
STORE 4 i
BYTE n
BYTE r
BYTE 0
BYTE t
BYTE y
BYTES 1 m
IN e i
DUMP_ARRAY i
SUBTRACT d
SHIFT
SUBTRACT d
MULTIPLY a
SHIFT
SUBTRACT d
MULTIPLY b
SHIFT
SUBTRACT d
MULTIPLY c
SHIFT
ADD
ADD
ADD
PUSH n
IN e i
DUMP_ARRAY i
SUBTRACT d
SHIFT
SUBTRACT d
MULTIPLY a
SHIFT
SUBTRACT d
MULTIPLY b
SHIFT
SUBTRACT d
MULTIPLY c
SHIFT
ADD
ADD
ADD
DUMP n
ADD
PUSH r
DIVIDE r a
DUP
TRUNC 0
FLIP
SUBTRACT
MUlTIPLY a
DUP
PUSH m
PUSH t
DIVIDE r b
DUP
TRUNC 0
FLIP
SUBTRACT
MUlTIPLY b
DUP
PUSH y
SUBTRACT t
DIVIDE a
PUSH m
DIVIDE r c
DUP
TRUNC 0
FLIP
SUBTRACT
MUlTIPLY c
DUP
PUSH t
SUBTRACT y
DIVIDE b
PUSH m
SUBTRACT r t
DIVIDE c
PUSH m
DUMP_ARRAY m
FLIP
ADD d
SHIFT
ADD d
SHIFT
ADD d
SHIFT
ADD d
SHIFT
OUTOF
PRINT
PRINTLN
answered Sep 13, 2018 at 23:42
\$\endgroup\$
3
\$\begingroup\$

BitCycle, 49 bytes

?Av
?v<> \Cv
~=B/Av
 ^+ <
+ B\^v /~v
 > /! <

Try it online!

Made so much more complicated by the signed numbers, otherwise it could just be:

?!
?^

This takes input and outputs as signed unary, though the -U flag is used to translate to decimal.

Explanation:

?Av From input 1
?v< And input 2
~=B Push positive numbers into the top B collector
 ^
+ B Invert bits of negative numbers and push into the bottom B collector
 > \ Filter one bit from each collector
 B/Av And the rest go into the A collector
 + < And then back into the B collectors
 B\^ If both positive and negative, then both bits are destroyed
 > / Otherwise they reflect off the > and go right of each of the \/
 > \Cv Collect the remainder of negative bits in the C collector
 Invert the bits and output
 v /~v Send one of the 0s to output to represent a negative number
 > /! < Positive remainders go straight to output
answered Apr 7, 2019 at 0:34
\$\endgroup\$
3
\$\begingroup\$

√ å ı \ ® Ï Ø ¿ , 4 bytes

II+o

Fairly basic program, as to be expected.

Explanation

I › Take input from the command line, evaluate and push to stack
 I › Take another input
 + › Add the two together and push to the stack
 o › Output the top value on the stack
answered Mar 15, 2017 at 16:28
\$\endgroup\$
3
\$\begingroup\$

Intcode, 22 bytes

3,0,3,1,1,0,1,2,4,2,99

Fairly basic. IO boilerplate takes up most of the bytecount, given that the language has addition as a builtin (1,0,1,2 would be a valid answer, if snippets were allowed)

answered Dec 24, 2019 at 1:43
\$\endgroup\$
3
\$\begingroup\$

Brainetry, 97 bytes

Golfed version:

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
a b c d
a
a b c d e f g h i
a b c d e f g

Does I/O like brainfuck programs, so you input ASCII codepoints and get ASCII characters as output, e.g. inputting two spaces (ASCII 32) the program pints @ (ASCII 64).

To try it online follow this repl.it link, paste the code in the btry/replit.btry file and hit the green "Run" button.

Golfed version was based off of this program:

This Brainetry program is a rather
simple one.
We just need to take two
integers as input from the user (ASCII codepoints)
and then we sum them.
Easier said than done,
right?
Wrong, this one is easy said AND done ;)
Just have to manipulate the inputs wisely.
answered Jun 14, 2020 at 14:15
\$\endgroup\$
3
\$\begingroup\$

ARM Thumb-2 machine code, 4 bytes

Machine code:

1840 4770

Assembly:

 .syntax unified
 .arch armv6t2
 .thumb
 .globl add
 .thumb_func
 // input: r0, r1
 // output: r0
add:
 // r0 += r1
 adds r0, r1
 // return
 bx lr

Boring, obvious solution.

It is a function, following the standard C calling convention.

uint32_t add(uint32_t r0, uint32_t r1);

The input is in r0 and r1, and the result is in r0.

answered Feb 10, 2021 at 19:33
\$\endgroup\$
3
\$\begingroup\$

TypeScript Compiler, 244 bytes

Yes, you read that right. Not TypeScript, but specifically its compiler.

type R<T,U,V>=T extends U?V:T
type N<T>=R<R<R<R<R<R<R<R<R<R<T,9,null>,8,9>,7,8>,6,7>,5,6>,4,5>,3,4>,2,3>,1,2>,0,1>
type P<T>=R<R<R<R<R<R<R<R<R<T,1,0>,2,1>,3,2>,4,3>,5,4>,6,5>,7,6>,8,7>,9,8>
type A<T,U>=T extends 0?U:A<P<T>,N<U>>
let x:A<1,2>=[]

Playground link

Enter the inputs as the type parameters of A (where I put 1 and 2) and the inferred type of x is their sum. It only takes one-digit inputs, and the output will be null if the addition overflows. It is in theory infinitely extendible, but in practice the compiler will just stop computing it if you allow numbers bigger than 20 (or 21 without overflow handling).

Because the inferred type gets erased by the compiler, I use the last three characters (=[]) to trigger a type error (TS2322), which contains the answer. For example, the error message may read

Type 'never[]' is not assignable to type '3'.

As for how this works:

R<T, U, V> returns V if T is U, and T otherwise.
N<T> returns T + 1. P<T> returns T - 1.
A<T, U> returns U if T is 0, and A<T - 1, U + 1> otherwise. Recursion!

One neat thing this can do is handle adding elements from two sets. For example, A<1|2,4|7> evaluates to 5 | 6 | 8 | 9.

answered Aug 28, 2021 at 14:12
\$\endgroup\$
2
  • \$\begingroup\$ Nice solution, but unfortunately this does not work for negative numbers, but I don't think it's possible at all with TypeScript's type system :/ Also, this is a much shorter solution for implementing addition with natural numbers: type T<N,U extends 0[]=[]>=U['length']extends N?U:T<N,[...U,0]>;type A<X,Y>=[...T<X>,...T<Y>]['length']: typescriptlang.org/play?#code/… \$\endgroup\$ Commented Oct 3, 2021 at 13:03
  • \$\begingroup\$ This isn't the only one that doesn't work for negatives, reading through the other answers. And I'll admit this probably isn't the shortest you can get, since this is just the addition part stripped out of my answer to the "Peano Arithmetic at Compile Time" challenge. \$\endgroup\$ Commented Oct 3, 2021 at 16:59
3
\$\begingroup\$

CATHY, 5 bytes

cAtHy

Try it Online!

answered Jun 26, 2022 at 22:02
\$\endgroup\$
3
\$\begingroup\$

Cubestack, 22 bytes

b' S S' y S S' y2 R y'

Try it Online!

Explanation:

b' # Push all inputs wrapped in a list (the array to iterate through)
 S S' # Push loop variable name (an empty string)
 y # Open for loop
 S S' y2 # Get the value of the loop variable
 R # Add
 y' # End for loop
answered Jun 27, 2022 at 1:06
\$\endgroup\$
3
\$\begingroup\$

Trianguish, 15 bytes

00000000: 1020 c301 a050 c008 b105 0c01 0710 19

Try it online!

answered Jul 29, 2022 at 23:20
\$\endgroup\$
3
\$\begingroup\$

Ultrarisky, 1 byte

I0{I

Try It Online!

Ultrarisky is a derivative of Risky made by Rydwolf Programs. While risky uses a 4-bit codepage (and thus has 16 commands that fit two to a byte) ultrarisky uses a two-bit codepage, and has 4 commands that fit four to a byte. It's quite hard to program in due to the lack of identity functions.

 0 # Add
I # One input
 {I # Absolute value of other input
The Thonnu
18.7k3 gold badges19 silver badges76 bronze badges
answered Feb 1, 2022 at 20:43
\$\endgroup\$
2
\$\begingroup\$

Minkolang 0.15, 5 bytes

nn+N.

Try it here.

Explanation

nn Take two numbers from input
 + Add
 N. Output as number and stop.
answered Jul 2, 2016 at 1:11
\$\endgroup\$
2
\$\begingroup\$

Silicon, 3 bytes

II+

Simple enough. Takes input and converts it to an integer twice and adds them together. Output is implicit.

answered Jul 2, 2016 at 9:07
\$\endgroup\$
2
\$\begingroup\$

Jolf, 1 byte

Interpreter.

u

Take sum of list.

Or, for two bytes, +j, takes two inputs seperated by double newline.

answered Jul 3, 2016 at 15:58
\$\endgroup\$
2
\$\begingroup\$

R, 13 bytes

scan()+scan()

Will ask twice for an input, and outputs the result of the sum.

Other possibility (18 bytes), using the sum function :

sum(scan(),scan())
answered Aug 26, 2016 at 16:29
\$\endgroup\$
1
  • \$\begingroup\$ sum(scan()) works as well \$\endgroup\$ Commented Mar 9, 2021 at 20:47
2
\$\begingroup\$

Codelike, 6 bytes

code:

ouuabe

breakdown:

o changes the direction that the code proceeds in, turning counterclockwise until it hits a command
 uu takes 2 integers from user input
 a adds the two integers together and pushes the result to the stack
 b prints the integer value at the top of the stack
 e ends the program

You can download the compiler here!

(Full disclosure, I did create this language and I did add the b command after reading this challenge but it was something I was already considering adding and it doesn't complete the challenge on its own so I feel that it doesn't violate the rules.)

answered Oct 6, 2016 at 1:29
\$\endgroup\$
1
  • 2
    \$\begingroup\$ Hi Connor! Welcome to the site. The language you created looks really interesting, well done. As for creating the language and making a change after seeing this problem, we usually allow such answers, but take them out of the running to win the challenge. Noting this fact, like you did, is exactly the right approach. In general, when you have questions like this, chat is a good place to ask. \$\endgroup\$ Commented Oct 6, 2016 at 5:28
2
\$\begingroup\$

SHENZHEN I/O MCxxxx assembly code, 35 bytes

slx x0
mov x0 acc
add x0
mov acc x0

Take the two numbers via XBus on x0, and send the result on x0

answered Oct 27, 2016 at 14:59
\$\endgroup\$
2
\$\begingroup\$

Ruby, 10 bytes

->a,b{a+b}

An anonymous Proc (I guess, if not a lambda idc) just adds its parameters. Makes use of implicit return in Ruby.

Usage: ->a,b{a+b}[1,2] or ->a,b{a+b}.call(1,2)

answered Oct 31, 2016 at 21:55
\$\endgroup\$
1 2
3
4 5
...
9

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.