67
\$\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>

\$\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\$
    – Dennis
    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\$
    – FinW
    Dec 4, 2016 at 11:56
  • 1
    \$\begingroup\$ @FinW Sure. As long as they don't get interpreted as octal. \$\endgroup\$
    – anna328p
    Dec 4, 2016 at 20:47

235 Answers 235

1 2
3
4 5
8
3
\$\begingroup\$

Perl 6, 3 bytes

*+*

A lambda that takes two arguments and returns their sum.

\$\endgroup\$
3
\$\begingroup\$

C, 19 bytes

f(a,b){return a+b;}
\$\endgroup\$
3
  • \$\begingroup\$ 17 bytes: f(a,b){b+=a;a=b;} \$\endgroup\$
    – jdt
    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\$
    – user58988
    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\$ 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
\$\endgroup\$
3
\$\begingroup\$

Japt, 1 byte

x

Here is a non-1 byte solution

U+V

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I read that as × at first and got really confused :P \$\endgroup\$ 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\$
    – Oliver
    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.

\$\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.
\$\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!

\$\endgroup\$
6
  • \$\begingroup\$ So the IP can spawn at any random position on the top row and left column of the playing field? \$\endgroup\$
    – MD XF
    Sep 26, 2017 at 4:08
  • \$\begingroup\$ @MDXF The ip can spawn anywhere including the top row and left column. \$\endgroup\$
    – Wheat Wizard
    Sep 26, 2017 at 4:15
  • \$\begingroup\$ So what happens if the location starts on @? \$\endgroup\$ 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\$
    – Wheat Wizard
    Oct 31, 2017 at 22:52
  • \$\begingroup\$ @WheatWizard Ah, didn't know about the % rule. Interesting language! \$\endgroup\$ Oct 31, 2017 at 23:11
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.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Wouldn't you still have to run it as sum <<< "98.342 77.123", or echo | sum? \$\endgroup\$ 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\$ 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\$
    – cnamejj
    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));
}
\$\endgroup\$
2
  • \$\begingroup\$ You can save 1 byte: a->b->a+b; \$\endgroup\$ 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\$ 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
\$\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
\$\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
\$\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)

\$\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.
\$\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.

\$\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.

\$\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\$
    – ruohola
    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\$
    – Bbrk24
    Oct 3, 2021 at 16:59
3
\$\begingroup\$

Lexurgy, 479 bytes

Port of @Toby Speight's answer. Input as a|b.

class b {\5,\6,\7}
class a {\1,\2,\3,\4,@b,\8}
a:
{@a,\9}$1 => A $1
b:
{@b,\8,\9}$1 => \4 $1
c:
{\8,\9}$1 => \4 $1
d:
{\2,\3,\6,\7}$1 => xx $1
e:
{\1,\3,\5,\7,\9} => x
f:
\4=>xxxx
g:
@a=>*
h:
*=>|/_ $
i propagate:
([]*)$1 A (x*)$2 | ([]*)$3 A (x*)$4 |=>$1 | $3 | A $2 $4
j:
|=>*
k propagate:
A x*10=>* xA
l:
Ax=>\-x
m:
xx=>\2
n:
x=>\1
o:
\2\2=>\4
p:
\4\4=>\8
q:
\8\1=>\9
r:
\2\1=>\3
s:
\4\2=>\6
t:
\4\3=>\7
u:
\4\1=>\5
v:
\-=>*
A=>\0

Lexurgy, 267 bytes, non-competing

Golfed version of the example adding machine. Input as a|b.

The general process is to increment each a digit by the value of the b digit, then handle any carries afterwards. Carries are denoted by a ', and increments the digit to its left when consumed.

As a result, this doesn't handle negative numbers, which the spec requires.

Class d {\0,\1,\2,\3,\4,\5,\6,\7,\8,\9}
Class i {\1,\2,\3,\4,\5,\6,\7,\8,\9,'\0}
a propagate:
` @d$1 | @d$2=>$2 ` $1 |/_ @d
then:
@d$1 | @d$2 * *=>| $2 ` $1 |/_ @d//` _
c propagate:
@d | @i => @i | @d
|0 => *
d:
{`,|}=>*
e propagate:
@d '=>@i *
'=>\1/$ _
\$\endgroup\$
3
\$\begingroup\$

CATHY, 5 bytes

cAtHy

Try it Online!

\$\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
\$\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.
\$\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.

\$\endgroup\$
2
\$\begingroup\$

Jolf, 1 byte

Interpreter.

u

Take sum of list.

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

\$\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())
\$\endgroup\$
1
  • \$\begingroup\$ sum(scan()) works as well \$\endgroup\$ Mar 9, 2021 at 20:47
2
\$\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
\$\endgroup\$
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.)

\$\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\$
    – isaacg
    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

\$\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)

\$\endgroup\$
2
\$\begingroup\$

TI-Basic, 2 bytes

Very straightforward.

sum(Ans
\$\endgroup\$
0
2
\$\begingroup\$

Kitanai, 15 bytes

add input input

Pretty straightforward :)

\$\endgroup\$
2
\$\begingroup\$

PigeonScript, 1 byte

+

Explanation: + pops the last two items from the stack, adds them, and pushes the result to the stack. Since there is nothing on the stack, the user is prompted for input twice. The inputs are pushed, popped, added, pushed, and the program ends, outputting what's on the stack (the result of input1 + input2)

\$\endgroup\$
1 2
3
4 5
8

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.