Add two numbers

47

15

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>

dkudriavtsev

Posted 2016-07-02T00:40:45.547

Reputation: 5 781

27This 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. – Dennis – 2016-07-02T00:48:43.650

2Can the answer take input with preceding zeros as default? e.g. 5 16 is inputted as 005 016 – FinW – 2016-12-04T11:56:08.650

1@FinW Sure. As long as they don't get interpreted as octal. – dkudriavtsev – 2016-12-04T20:47:04.670

Answers

43

Jelly, 1 byte

+

Try it online!

Also works in 05AB1E, Actually, APL, Braingolf, ,,, (Commata), Factor, Forth, Implicit, J, Julia, K, kdb+, Keg, Ly, MathGolf, MATL, Pyke, Deorst, and Q.

Dennis

Posted 2016-07-02T00:40:45.547

Reputation: 196 637

4Also works in Swift. – Zacharý – 2017-09-09T14:23:12.803

4Pyth as well @Zacharý – Stan Strum – 2017-10-09T00:18:55.237

@StanStrum This does not work in Pyth, it adds the first input to itself in Pyth. – isaacg – 2020-02-01T00:18:53.350

@isaacg Nice to see the Pyth lord pop up in my inbox again. My understanding of Pyth was always a little rusty, thank you. – Stan Strum – 2020-02-01T04:05:11.850

70

Minecraft 1.10, 221 characters (non-competing)

See, this is what we have to deal with when we make Minecraft maps.

Aside: There's no way to take a string input in Minecraft, so I'm cheating a bit by making you input the numbers into the program itself. (It's somewhat justifiable because quite a few maps, like Lorgon111's Minecraft Bingo, require you to copy and paste commands into chat in order to input a number.)

Thank you abrightmoore for the Block Labels MCEdit filter.

a

scoreboard objectives add a dummy
scoreboard players set m a 6
scoreboard players set n a 8
scoreboard players operation r a += m a
scoreboard players operation r a += n a
tellraw @a {"score":{"name":"r","objective":"a"}}

Non-competing due to difficulties in input, and I have no idea how to count bytes in this thing (the blytes system is flawed for command blocks).

quat

Posted 2016-07-02T00:40:45.547

Reputation: 1 211

4This is by far the best one. Amazing. – dkudriavtsev – 2016-07-03T01:13:02.260

I don't think that hardcoding the inputs is valid, but I don't know enough about command blocks in Minecraft to be able to judge if there's a way to take input other than hardcoding. Perhaps one of our resident Minecraft experts could weigh in. – Mego – 2016-07-04T02:13:34.947

3Yeah, there's zero text input in MC, besides "please copy and paste this command". A number keypad is possible with a /tellraw, but will be barely usable all golfed, not to mention 500kb thanks to /tellraw's obscenely strict syntax. I guess an alternative would be for it to count something in-world, like pigs+cows, or red wool+blue wool. – quat – 2016-07-04T05:51:27.733

1@quat As we're usually using hopper to count things in minecraft, I guesse it would be the way to go. An other way to deal with this would be doable in pure redstone too by using levers. As we don't have any restriction, and the bit is the biggest natural value reachable in minecraft, that would result in simply adding two bits with an output of two bits (possibility : 0,1,2. An other solution would be to take in 2 bytes and output on 9 wire, but would be much less golfy. – Katenkyo – 2016-07-04T07:08:01.020

I've added an answer here that is input-capable.

– Addison Crump – 2016-07-06T07:01:30.523

2There is now an MC Standard for bytecount. – mbomb007 – 2016-10-10T20:23:27.850

Why not use comparators reading item frames? They output a redstone signal based on the rotation of the item. – programmer5000 – 2017-03-28T20:57:46.357

Are MCEdits what they call edits over at MacDonald's.SE? – caird coinheringaahing – 2017-06-29T07:02:23.647

@cairdcoinheringaahing MCEdit is a Minecraft map editor – dkudriavtsev – 2017-08-07T00:36:46.293

Umm, are y'all aware of /trigger? – Redwolf Programs – 2018-08-26T14:03:25.433

42

Binary lambda calculus, 4.125 bytes

Input and output as Church numerals.

00000000 01011111 01100101 11101101 0

In lambda calculus, it is λm. λn. λf. λx. m f (n f x).

De Bruijn index: λ λ λ λ 4 2 (3 2 1)


Lambda calculus is a concise way of describing a mapping (function).

For example, this task can be written as λx. λy. x + y

The thing to note is, that this is not a lambda (function) which takes two arguments. This is actually a nested lambda. However, it behaves like a lambda which takes two arguments, so it can be informally described as such. Every lambda formally only takes one argument.

For example, if we apply this lambda to 3 and 4:

x. λy. x + y) 3 4 ≡ (λy. 3 + y) 4 ≡ 3 + 4 = 7

So, the first lambda actually returns another lambda.


Church numerals is a way of doing away with the extra signs, leaving with only lambda symbols and variables.

Each number in the Church system is actually a lambda that specifies how many times the function is applied to an item.

Let the function be f and the item be x.

So, the number 1 would correspond to λf. λx. f x, which means apply f to x exactly once.

The number 3, for example, would be λf. λx. f (f (f x)), which means apply f to x exactly three times.


Therefore, to add two Church numerals (say, m and n) together, it is the same as applying f to x, m + n times.

We can observe that this is the same as first applying f to x, n times, and then applying f to the resulting item m times.

For example, 2 would mean f(f(x)) and 3 would mean f(f(f(x))), so 2 + 3 would be f(f(f(f(f(x))))).

To apply f to x, n times, we have n f x.

You can view m and n as functions taking two arguments, informally.

Then, we apply f again to this resulting item, m times: m f (n f x).

Then, we add back the boilerplate to obtain λm. λn. λf. λx. m f (n f x).


Now, we have to convert it to De Bruijn index.

Firstly, we count the "relative distance" between each variable to the lambda declaration. For example, the m would have a distance of 4, because it is declared 4 lambdas "ago". Similarly, the n would have a distance of 3, the f would have a distance of 2, and the x would have a distance of 1.

So, we write it as this intermediate form: λm. λn. λf. λx. 4 2 (3 2 1)

Then, we remove the variable declarations, leaving us with: λ λ λ λ 4 2 (3 2 1)


Now, we convert it to binary lambda calculus.

The rules are:

  • λ becomes 00.
  • m n (grouping) becomes 01 m n.
  • numbers i becomes 1 i times + 0, for example 4 becomes 11110.

λ λ λ λ 4 2 (3 2 1)

≡ λ λ λ λ 11110 110 (1110 110 10)

≡ λ λ λ λ 11110 110 0101 111011010

≡ λ λ λ λ 0101 111101100101111011010

00 00 00 00 0101 111101100101 111011010

000000000101111101100101111011010

Leaky Nun

Posted 2016-07-02T00:40:45.547

Reputation: 45 011

19I would like to see the 4.125 byte source file that you pass to the interpreter/compiler. – Martin Ender – 2016-07-02T06:41:52.133

8

@MartinEnder Say that to every answer here.

– Leaky Nun – 2016-07-02T07:09:27.703

5I would like to see a 0.875 byte solution please. – Mr Lister – 2016-07-03T09:42:26.820

4By meta consensus, unless you can store the program as a file with a fractional amount of bytes, you have to round up. – Pavel – 2017-01-24T16:11:09.197

25

Common Lisp, 15 bytes

(+(read)(read))

Byeonggon Lee

Posted 2016-07-02T00:40:45.547

Reputation: 419

2Welcome to Programming Puzzles & Code Golf! – Dennis – 2016-07-03T01:06:03.900

I'm relatively unfamiliar with CLisp, but would it be possible to remove the spaces? (+(read)(read)) – Mego – 2016-07-03T01:39:14.510

@Mego You're right, it is possible. I didn't know that because I'm also new to Common Lisp, thanks for the info! I edited the source – Byeonggon Lee – 2016-07-03T02:57:07.613

3I guess we both learned something here! Welcome aboard to PPCG! – Mego – 2016-07-03T03:20:48.190

21

Stack Cats, 8 + 4 = 12 bytes

]_:]_!<X

Run with the -mn flags. Try it online!

Golfing in Stack Cats is highly counterintuitive, so this program above was found with a few days of brute forcing. For comparison, a more intuitive, human-written solution using the *(...)> template is two bytes longer

*(>-_:[:)>

with the -ln flags instead (see the bottom of this post for an explanation).

Explanation

Here's a primer on Stack Cats:

  • Stack Cats is a reversible esoteric language where the mirror of a snippet undoes the effect of the original snippet. Programs must also be mirror images of itself — necessarily, this means that even-length programs are either no-ops or infinite loops, and all non-trivial terminating programs are of odd length (and are essentially a conjugation of the central operator).
  • Since half the program is always implied, one half can be left out with the -m or -l flag. Here the -m flag is used, so the half program above actually expands to ]_:]_!<X>!_[:_[.
  • As its name suggests, Stack Cats is stack-based, with the stacks being bottomless with zeroes (i.e. operations on an otherwise empty stack return 0). Stack Cats actually uses a tape of stacks, e.g. < and > move one stack left and one stack right respectively.
  • Zeroes at the bottom of the stack are swallowed/removed.
  • All input is pushed to an initial input stack, with the first input at the top and an extra -1 below the last input. Output is done at the end, using the contents of the current stack (with an optional -1 at the bottom being ignored). -n denotes numeric I/O.

And here's a trace of the expanded full program, ]_:]_!<X>!_[:_[:

    Initial state (* denotes current stack):
      ... [] [-1 b a]* [] [] ...
]   Move one stack right, taking the top element with you
      ... [] [-1 b] [a]* [] ...
_   Reversible subtraction, performing [x y] -> [x x-y] (uses an implicit zero here)
      ... [] [-1 b] [-a]* [] ...
:   Swap top two
      ... [] [-1 b] [-a 0]* [] ...
]   Move one stack right, taking the top element with you
      ... [] [-1 b] [-a] []* ...
_   Reversible subtraction (0-0, so no-op here)
!   Bit flip top element, x -> -x-1
      ... [] [-1 b] [-a] [-1]* ...
<   Move one stack left
      ... [] [-1 b] [-a]* [-1] ...
X   Swap the stack to the left and right
      ... [] [-1] [-a]* [-1 b] ...
>   Move one stack right
      ... [] [-1] [-a] [-1 b]* ...
!   Bit flip
      ... [] [-1] [-a] [-1 -b-1]* ...
_   Reversible subtraction
      ... [] [-1] [-a] [-1 b]* ...
[   Move one stack left, taking the top element with you
      ... [] [-1] [-a b]* [-1] ...
:   Swap top two
      ... [] [-1] [b -a]* [-1] ...
_   Reversible subtraction
      ... [] [-1] [b a+b]* [-1] ...
[   Move one stack left, taking the top element with you
      ... [] [-1 a+b]* [b] [-1] ...

a+b is then outputted, with the base -1 ignored. Note that the trickiest part about this solution is that the output stack must have a -1 at the bottom, otherwise an output stack of just [-1] would ignore the base -1, and an output stack of [0] would cause the base zero to be swallowed (but an output stack of [2], for example, would output 2 just fine).


Just for fun, here's the full list of related solutions of the same length found (list might not be complete):

]_:]^!<X
]_:]_!<X
]_:]!^<X
]_:!]^<X
[_:[^!>X
[_:[_!>X
[_:[!^>X
[_:![^>X

The *(>-_:[:)> solution is longer, but is more intuitive to write since it uses the *(...)> template. This template expands to <(...)*(...)> when used with the -l flag, which means:

<       Move one stack left
(...)   Loop - enter if the top is positive and exit when the top is next positive again
        Since the stack to the left is initially empty, this is a no-op (top is 0)
*       XOR with 1 - top of stack is now 1
(...)   Another loop, this time actually run
>       Move one stack right

As such, the *(...)> template means that the first loop is skipped but the second is executed. This allows more straightforward programming to take place, since we don't need to worry about the effects of the loop in the other half of the program.

In this case, the inside of the loop is:

>       Move one stack right, to the input stack
-       Negate top, [-1 b a] -> [-1 b -a]
_       Reversible subtraction, [-1 b -a] -> [-1 b a+b]
:       Swap top two, [-1 b a+b] -> [-1 a+b b]
[       Move one stack left, taking top of stack with you (removing the top b)
:       Swap top two, putting the 1 on this stack on top again

The final > in the template then moves us back to the input stack, where a+b is outputted.

Sp3000

Posted 2016-07-02T00:40:45.547

Reputation: 58 729

20

Brain-flak, 6 bytes

({}{})

Try it online!

Brain-flak is a really interesting language with two major restrictions on it.

  1. The only valid characters are brackets, i.e. any of these characters:

    (){}[]<>
    
  2. Every single set of brackets must be entirely matched, otherwise the program is invalid.

A set of brackets with nothing between them is called a "nilad". A nilad creates a certain numerical value, and all of these nilads next to each other are added up. A set of brackets with something between them is called a "monad". A monad is a function that takes an numerical argument. So the brackets inside a monad are evaluated, and that is the argument to the monad. Here is a more concrete example.

The () nilad equals 1. So the following brain-flak code:

()()()

Is evaluated to 3. The () monad pushes the value inside of it on the global stack. So the following

(()()())

pushes a 3. The {} nilad pops the value on top of the stack. Since consecutive nilads are always added, a string of {} sums all of the top elements on the stack. So my code is essentially:

push(pop() + pop())

James

Posted 2016-07-02T00:40:45.547

Reputation: 54 537

15

Dominoes, 38,000 bytes or 37 tiles

This is created in Tabletop Simulator. Here is a video and here is the file. It is a standard half-adder, composed of an and gate for the 2^1 place value and an xor gate for the 2^0 place value.

enter image description here

Details

  • I/O
    • Start - This is included for clarity (not counted towards total) and is what 'calls' or 'executes' the function. Should be 'pressed' after input is given [Yellow].
    • Input A - This is included for clarity (not counted towards total) and is 'pressed' to indicated a 1 and unpressed for 0 [Green].
    • Input B - This is included for clarity (not counted towards total) and is 'pressed' to indicated a 1 and unpressed for 0 [Blue].
    • Output - This is counted towards total. These dominoes declare the sum. The left is 2^1 and the right is 2^0 [Black].
  • Pressing
    • To give input or start the chain, spawn the metal marble
    • Set the lift strength to 100%
    • Lift the marble above the desired domino
    • Drop the marble

NonlinearFruit

Posted 2016-07-02T00:40:45.547

Reputation: 5 334

1

...how?

– dkudriavtsev – 2017-03-14T05:13:31.173

4

@Mendeleev Once you have all the binary logic gates, everything else falls into place xD.

– NonlinearFruit – 2017-03-14T12:13:48.410

15

Minecraft 1.10.x, 924 512 bytes

Thanks to @quat for reducing the blytecount by 48 points and the bytecount by 412.

Alright, so, I took some of the ideas from this answer and made a version of my own, except that this one is capable of accepting non-negative input. A version may be found here in structure block format.

group

(new version looks kinda boring tbh)

Similar commands as the other answer:

scoreboard objectives add a dummy
execute @e[type=Pig] ~ ~ ~ scoreboard players add m a 1
execute @e[type=Cow] ~ ~ ~ scoreboard players add n a 1
scoreboard players operation n a += m a
tellraw @a {"score":{"name":"n","objective":"a"}}

To input numbers, spawn in a number of cows and pigs. Cows will represent value "n" and pigs will represent value "m". The command block system will progressively kill the cows and pigs and assign values as necessary.

This answer assumes that you are in a world with no naturally occurring cows or pigs and that the values stored in "n" and "m" are cleared on each run.

Addison Crump

Posted 2016-07-02T00:40:45.547

Reputation: 10 763

For negative integers, you could use 2 other kinds of animals as "neganimals" - 5 horses could represent -5, for example. – Mego – 2016-07-06T09:32:49.543

@Mego Then it would be four inputs, not 2. – Addison Crump – 2016-07-06T22:52:20.523

It would still be two inputs - it's the equivalent of using two's complement for negative numbers. Slightly different format, but still one input. At least, that's my two cents. – Mego – 2016-07-07T00:07:09.470

Might be able to save on blocks by using execute @e[type=Pig] ~ ~ ~ scoreboard players add m a 1, so you don't need any form of clock. – quat – 2016-07-07T20:57:04.167

@quat Ooh. Nice. – Addison Crump – 2016-07-07T20:58:14.980

There is now an MC Standard for bytecount. We no longer use "blytes". – mbomb007 – 2016-10-10T20:25:03.290

@mbomb007 I'd already listed it, and I actually wrote that post, but I this it a bit clearer. Thanks. ;) – Addison Crump – 2016-10-11T00:30:19.307

14

Retina, 42 bytes

\d+
$*
T`1p`-_` |-1+
+`.\b.

^(-)?.*
$1$.&

Try it online!

Explanation

Adding numbers in unary is the easiest thing in the world, but once you introduce negative numbers, things get fiddly...

\d+
$*

We start by converting the numbers to unary. This is done by matching each number with \d+ and replacing it with $*. This is a Retina-specific substitution feature. The full syntax is count$*character and inserts count copies of character. Both of those can be omitted where count defaults to $& (i.e. the match itself) and character defaults to 1. So for each input n we get n ones, and we still have potential minus signs in there, as well as the space separator. E.g. input 8 -5 gives:

11111111 -11111

Now in order to deal with negative numbers it's easiest to use a separate -1 digit. We'll use - for that purpose.

T`1p`-_` |-1+

This stage does two things. It gets rid of the space, the leading minus signs, and turns the 1s after a minus sign into - themselves. This is done by matching |-1+ (i.e. either a space or a negative number) and performing a transliteration on it. The transliteration goes from 1p to -_, but here, p expands to all printable ASCII characters and _ means delete. So 1s in those matches get turned into -s and minuses and spaces get removed. Our example now looks like this:

11111111-----
+`.\b.

This stage handles the case where there's one positive and one negative number in the input. If so, there will be 1s and -s in the string and we want them to cancel. This is done by matching two characters with a word-boundary between them (since 1s is considered a word character and - isn't), and replacing the match with nothing. The + instructs Retina to do this repeatedly until the string stops changing.

Now we're left with only 1s or only -s.

^(-)?.*
$1$.&

To convert this back to decimal, we match the entire input, but if possible we capture a - into group 1. We write back group 1 (to prepend a - to negative numbers) and then we write back the length of the match with $.& (also a Retina-specific substitution feature).

Martin Ender

Posted 2016-07-02T00:40:45.547

Reputation: 184 808

2This is very clever. – Mego – 2016-07-04T02:14:58.393

Now if only there were an easy way to implement range in Retina. I've tried a few times, but the negatives are a pain. – mbomb007 – 2016-07-06T18:33:43.377

It takes over 40 bytes to add two numbers in this language?? – dkudriavtsev – 2016-09-24T02:10:54.540

2@DmitryKudriavtsev well, Retina has no concept of numbers... – Martin Ender – 2016-09-24T07:42:18.433

@DmitryKudriavtsev, and that's just integers.... – msh210 – 2016-10-31T09:15:52.570

@wat If it were restricted to non-negatives, it'd be much shorter. – mbomb007 – 2017-01-09T16:42:58.927

10

Mathematica, 4 2 bytes

Tr

Crossed out 4 is still regular 4... Tr applied to a one-dimensional list takes the sum of said list's elements.

LegionMammal978

Posted 2016-07-02T00:40:45.547

Reputation: 15 731

10

Haskell, 3 bytes

(+)

The parentheses are here because it needs to be an prefix function. This is the same as taking a section of the + function, but no arguments are applied. It also works on a wide range of types, such as properly implemented Vectors, Matricies, Complex numbers, Floats, Doubles, Rationals, and of course Integers.

Because this is Haskell, here is how to do it on the type-level. This will be done at compile time instead of run time:

-- This *type* represents Zero
data Zero
-- This *type* represents any other number by saying what number it is a successor to.
-- For example: One is (Succ Zero) and Two is (Succ (Succ Zero))
data Succ a

-- a + b = c, if you have a and b, you can find c, and if you have a and c you can find b (This gives subtraction automatically!)
class Add a b c | a b -> c, a c -> b

-- 0 + n = n 
instance Add Zero n n
-- If (a + b = c) then ((a + 1) + b = (c + 1))
instance (Add a b c) => Add (Succ a) b (Succ c)

Code adapted from Haskell Wiki

Lazersmoke

Posted 2016-07-02T00:40:45.547

Reputation: 291

3fun fact: this is a polyglot with Cheddar :D – Downgoat – 2016-07-17T22:15:33.567

9

Shakespeare Programming Language, 155 152 bytes

.
Ajax,.
Ford,.
Act I:.
Scene I:.
[Enter Ajax and Ford]
Ajax:
Listen to thy heart
Ford:
Listen to THY heart!You is sum you and I.Open thy heart
[Exeunt]

Ungolfed:

Summing Two Numbers in Verona.

Romeo, a numerical man.
Juliet, his lover and numerical counterpart.

Act I: In which Italian addition is performed.

Scene I: In which our two young lovers have a short chat.

[Enter Romeo and Juliet]

Romeo:
  Listen to thy heart.

Juliet:
  Listen to THY heart! Thou art the sum of thyself and I. Open thy heart.

[Exeunt]

I'm using drsam94's SPL compiler to compile this. To test:

$ python splc.py sum.spl > sum.c
$ gcc sum.c -o sum.exe
$ echo -e "5\n16" | ./sum
21

Copper

Posted 2016-07-02T00:40:45.547

Reputation: 3 684

Just warning you, this is not valid SPL. “You is sum you and I.” is not valid in the actual compiler. I’m not sure where you got the compiler you’re using. In the actual compiler you can save some bytes with “Listen tothy.” and “Open heart” – Hello Goodbye – 2020-01-07T14:45:32.477

8

Geometry Dash - 15 objects

Finally done.
15 objects aren't much, but it was still a nightmare to do this (especially because of the negative numbers).

enter image description here

Because I would have to insert 15 images here for how to reproduce this, I just uploaded the level. The level ID is 5216804. The description tells you how to run it and you can copy it since it is copyable.

Explanation:

The top-left trigger (Instant Count 2) checked if the first addend was 0. If it was, it then checked if the second addend was positive or negative. If it was positive, it transferred the value from the second addend to the sum (BF-style, using loops) and if it was negative, it would do the same thing.

The reason why we need to check if the second addend is positive or negative is that we would need to subtract one from the second addend and add one to the sum or add one to the second addend and subtract one from the sum respectively.

If the first addend is not zero, it tests whether it is positive or negative using the process above. After one iteration in the while loop, it tests to see if the first addend is zero and if it is, it does the process described at the beginning of the explanation.

Since Geometry Dash is remarkably similar to BF, you could make a BF solution out of this.

MilkyWay90

Posted 2016-07-02T00:40:45.547

Reputation: 2 264

8

JavaScript (ES6), 9 bytes

a=>b=>a+b

Patrick Roberts

Posted 2016-07-02T00:40:45.547

Reputation: 2 475

I don't think a nested function counts as a two-input function in javascript – proud haskeller – 2016-07-05T16:34:33.403

4

@proudhaskeller yes it does

– Patrick Roberts – 2016-07-05T16:45:53.437

1This one works in C# also. – Grax32 – 2016-10-12T17:59:48.560

8

Brachylog, 2 bytes

+.

Expects a list with the two numbers as input

Alternatively, if you want the answer to STDOUT:

+w

Fatalize

Posted 2016-07-02T00:40:45.547

Reputation: 32 976

8

dc, 2 bytes

+f

Adds top two items on stack (previously taken from stdin), then dumps the stack's contents to stdout.

EDIT: Upon further consideration, it seems there are several ways this might be implemented, depending on the desired I/O behaviour.

+        # adds top two items and pushes on stack
+n       # adds top two and prints it, no newline, popping it from stack
+dn      # ditto, except leaves result on stack
??+      # takes two inputs from stdin before adding, leaving sum on stack

I suppose the most complete form for the sum would be this:

??+p     # takes two inputs, adds, 'peeks'
         #  (prints top value with newline and leaves result on stack)

Wait! Two numbers can be taken on the same line, separated by a space! This gives us:

?+p

Joe

Posted 2016-07-02T00:40:45.547

Reputation: 895

I can't see how to use the first example +f , dc -e "?+p" works ok here. – Jasen – 2017-01-09T21:38:06.020

1@Jasen The +f version works if you've already put (exactly two) numbers on the stack. I didn't really know whether dc's I/O is supposed to be std(in|out) or the stack. In retrospect, that was the least sensible option to put at the top of the post. :/ – Joe – 2017-01-10T06:12:50.790

the rules say stack is OK so far as I can tell, – Jasen – 2017-01-10T07:04:14.523

7

Python, 11 3 bytes

sum

int.__add__

A simple special operator.

Leaky Nun

Posted 2016-07-02T00:40:45.547

Reputation: 45 011

7

PHP, 20 bytes

Surprisingly short this time:

<?=array_sum($argv);

Runs from command line, like:

$ php sum.php 1 2

insertusernamehere

Posted 2016-07-02T00:40:45.547

Reputation: 4 551

Your script also accepts php sum.php 1 2 3 4 5 6 so I'm not 100% sure if that's ok. – timmyRS – 2016-10-06T16:43:58.553

@timmyRS The submission should work for a specific input format – two integers. I don't think it should handle other inputs, too. – insertusernamehere – 2016-10-06T17:02:16.187

What if the source file name starts with a digit? :) – Alex Howansky – 2016-10-12T17:57:01.970

@AlexHowansky Psssssssst – don't tell anybody. ;) This is the quirk, when running from a file. You can still execute it using the -r flag – then it's not a problem anymore. – insertusernamehere – 2016-10-12T17:59:34.380

7

Cheddar, 3 bytes

(+)

This is a cool feature of Cheddar called "functionized operators". Credit for this idea goes to @CᴏɴᴏʀO'Bʀɪᴇɴ.

Here are more examples of functionized operators:

(+)(1,2) // 3
(/)(6,2) // 3
(-)(5)   // -5

Downgoat

Posted 2016-07-02T00:40:45.547

Reputation: 27 116

6

C, 35 bytes

s(x,y){return y?s(x^y,(x&y)<<1):x;}

What I've done here is defined addition without the use of boolean or arithmetic operators. This recursively makes x the sum bits by 'xor', and y the carry bits by 'and' until there is no carry. Here's the ungolfed version:

int sum(int x,int y){
    if(y==0){
        //anything plus 0 is itself
        return x;
    }
    //if it makes you happier imagine there's an else here
    int sumBits=x^y;
    int carryBits=(x&y)<<1;
    return sum(sumBits,carryBits);
}

Bijan

Posted 2016-07-02T00:40:45.547

Reputation: 781

Why don't you just add directly? – Esolanging Fruit – 2017-03-19T19:51:27.150

1I found that to be boring, the fully golfed version is trivial. – Bijan – 2017-03-19T21:56:27.127

1

"All answers should show some effort towards reaching a better score. For instance, answers to code golf challenges should try to be as short as possible (within the constraints of the chosen language)." (from https://codegolf.meta.stackexchange.com/a/7073/61384)

– Esolanging Fruit – 2017-03-20T02:12:28.083

4Obviously I thought of just adding the numbers, and I did put effort into making it shorter, only under alternate restraints. I think since this is an unconventional question, it deserves an unconventional answer. Following that rule word for word, there would be no reason to ever put up an answer if someone has already put up a shorter one. If you put up your 20 byte python solution and someone already has a 4 byte version up then you're proving that you don't know how to copy and paste. People put up 20 byte solutions, because we value originality. – Bijan – 2017-03-20T03:40:42.650

2It is implied that it is competitive in the language you are choosing. However, having read up on meta, it seems that I cannot claim that your answer is invalid ("An answer may implement any algorithm, even if golfier ones exist"), so I guess I'll drop it. – Esolanging Fruit – 2017-03-20T05:00:16.767

6

MATL, 1 byte

s

Accepts an array of two integers as input and sums them. While the simple program of + also works, that has already been shown for other languages.

Try it Online

Suever

Posted 2016-07-02T00:40:45.547

Reputation: 10 257

5

PowerShell v2+, 17 bytes

$args-join'+'|iex

Takes input as two separate command-line arguments, which get pre-populated into the special array $args. We form a string with the -join operator by concatenating them together with a + in the middle, then pipe that string to Invoke-Expression (similar to eval).


Thanks to @DarthTwon for reminding me that when dealing with such minimal programs, there are multiple methods of taking input all at the same byte-count.

$args[0]+$args[1]
param($a,$b)$a+$b

PowerShell is nothing if not flexible.

AdmBorkBork

Posted 2016-07-02T00:40:45.547

Reputation: 41 581

1Yeah, I'm just stalking you here :P Alternate answers: $args[0]+$args[1] and param($a,$b)$a+$b – ThePoShWolf – 2016-07-27T15:32:02.670

5

Batch, 25 18 16 bytes

@cmd/cset/a%1+%2

Edit: saved 7 9 bytes by using my trick from Alternating Sign Sequence.

Neil

Posted 2016-07-02T00:40:45.547

Reputation: 95 035

5

><>, 7 6 3 bytes

+n;

Online interpreter

Or try it on TIO with the -v flag.

Try it online

Emigna

Posted 2016-07-02T00:40:45.547

Reputation: 50 798

Since the question lets you define a function, I believe a simple + would be enough : it would pop two numbers from the stack and put the result of their addition back on the stack. The cost of -v could also be avoided, since reading the numbers could have been done beforehand the function invocation. – Aaron – 2016-07-04T07:22:29.347

1@Aaron: True. But as that solution is already posted for several other languages already I'll keep this as a full program. – Emigna – 2016-07-04T08:48:14.457

1

I thought the v flag would be a maximum of +1 byte but either way you could use the fishlanguage.com interpreter and your total would be 3 bytes (it doesn't need -v).

– redstarcoder – 2017-01-09T15:53:10.223

@redstarcoder: Everyone always specifies the flag as 3 bytes for fish (and 1 byte for all other languages it seems). Not sure why it's different but I assume it is for a valid reason. – Emigna – 2017-01-09T20:10:07.053

Regardless, you don't need the flag if you just use the fishlanguage.com interpreter. Do you have a link to the meta? I haven't seen any ><> program get added bytes for using integers on the initial stack (I've done it too). – redstarcoder – 2017-01-09T20:22:07.090

@redstarcoder: I've searched several times and not found a meta on it. Some people seem to add 3 bytes for the v-flag and some don't. I suppose if you use fishlanguage which allows for implicit stack-filling you can ignore it and using TIO you need it. – Emigna – 2017-01-09T20:34:40.077

5

Perl 5.10, 8 bytes

The two numbers to add must be on 2 separate lines for this one to work:

say<>+<>

Try this one here.

One with input on the same line (14 + 1 bytes for -a flag)

say$F[0]+$F[1]

Try it here!

One with input on the same line (19 + 1 bytes for -a flag)

map{$s+=$_}@F;say$s

Try this one here.

Another one, by changing the array default separator (19 + 1 bytes for -a flag as well)

$"="+";say eval"@F"

Try this one here!

Paul Picard

Posted 2016-07-02T00:40:45.547

Reputation: 863

2

Hey, another good example (if this will end up being a catalogue challenge) is the method outlined by Dennis in this post: http://codegolf.stackexchange.com/q/32884 (ab)using the the -p flag.

– Dom Hastings – 2016-07-13T15:51:23.070

Instead of say$F[0]+$F[1], say pop()+pop works (tested in Strawberry 5.20.2 with -E) and saves you a byte. – msh210 – 2016-10-31T09:11:47.533

5

Fuzzy Octo Guacamole, 1 byte

a

A function that takes inputs from the top of the stack and outputs by pushing to the stack.

Example running in the REPL:

>>> 8 9 :
[8,9]
>>> a :
17

Rɪᴋᴇʀ

Posted 2016-07-02T00:40:45.547

Reputation: 7 410

4

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.

James

Posted 2016-07-02T00:40:45.547

Reputation: 54 537

4

Add++, 7 bytes

+?
+?
O

Try it online!

+? adds the input to the accumulator and the O outputs it as a number.

A function is 1 byte longer at

D,f,@@,+

caird coinheringaahing

Posted 2016-07-02T00:40:45.547

Reputation: 13 702

Weird, I would've thought a language called Add++ would be at... well... adding :D – Beta Decay – 2017-06-04T21:39:33.857

Right tool for the job – Robert Fraser – 2017-08-06T08:55:24.457

4

Piet - 5 Codels

I didn't see one in Piet, so I decided to post one.

It's really the code!

Hold on, let me scale that up a bit for you to see.

Codel size 25

The codel size is 25.

I tested this on npiet. When run, the program will ask for a number, then for another, and then print it out. Due to the nature of Piet, it will continue this cycle until you interrupt it.

There are 17 other variants of the same code. Everything is relative in Piet, so changing the start color will change the rest of the colors. Breaking down the code is as follows:

Light Red - Does nothing.

Dark Blue (hue shift 4, darkness shift 2) - Pushes a number from STDIN.

Green (hue shift 4, darkness shift 2) - Pushes a number from STDIN.

Teal (hue shift 1, darkness shift 0) - Pushes the sum of the top two numbers in the stack.

Dark Green (hue shift 5, darkness shift 1) - Writes top of stack to STDOUT as a number.

justanotherbadprogrammer

Posted 2016-07-02T00:40:45.547

Reputation: 41

4

MATLAB, 4 bytes

1 byte removed thanks to @LeakyNun

@sum

This is an anonymous function that takes an array and gives the sum. Example use:

>> f = @sum
f = 
    @sum
>> f([3 4])
ans =
     7

Luis Mendo

Posted 2016-07-02T00:40:45.547

Reputation: 87 464

What about sum? – Leaky Nun – 2016-07-02T02:06:46.827

@LeakyNun Thanks, good idea! – Luis Mendo – 2016-07-02T09:56:36.053

43 bytes? xD BTW: I thought we have to have full program or a function, so I'd say only @sum is a valid answer. Or is there another meta consensus? – flawr – 2016-07-02T18:19:16.190

@flawr I think there is, yes. But I couldn't find it – Luis Mendo – 2016-07-02T18:20:56.357

I think I found it @flawr http://meta.codegolf.stackexchange.com/q/7205/36398

– Luis Mendo – 2016-07-02T18:23:39.777

I'm still thinking about it, I do still have the notion that you have to have an expression, that evaluates to a function should in this case be @sum as sum does IMO not evaluate to a function. How would you interpret that? – flawr – 2016-07-02T19:36:42.700

@flawr Yes, I'm not sure either. I've added the @ – Luis Mendo – 2016-07-03T02:31:27.153

4Wooah, I helped you reduce from 43 to 4 bytes XD – flawr – 2016-07-03T10:34:00.217

4

C# - 11 10 bytes

a=>b=>a+b;

Apparently works in ES6 with no semicolon: 10 bytes

(a,b)=>a+b

A lambda expression.

Yytsi

Posted 2016-07-02T00:40:45.547

Reputation: 3 582

Also valid in ES6 – proud haskeller – 2016-07-05T16:34:00.080

You missed the ending ; – aloisdg moving to codidact.com – 2016-07-10T14:16:15.477

@aloisdg I was unsure whether I should add a semicolon to end it or not :P Edited. – Yytsi – 2016-07-10T14:24:43.600

@TuukkaX I think we should use it. It feels more valid. :) – aloisdg moving to codidact.com – 2016-07-10T14:40:10.670

@aloisdg Techinally it is required in this case, so I'll keep it. – Yytsi – 2016-07-10T14:52:30.340

@TuukkaX I added it to golfing tips.

– aloisdg moving to codidact.com – 2016-07-10T15:13:44.263

If you change from C# to ES6, then removing the semicolon would be considered valid – Patrick Roberts – 2016-07-17T18:08:47.220

Is this the argument to a delegate like Func<int, int, int>? That's valid for golfing purposes? – Tyler StandishMan – 2016-08-27T13:11:19.190

@TylerStandishMan Correct. Also, they're allowed :) – Yytsi – 2016-08-27T16:03:52.407

4

GoLScript, 1 byte (non-competiting)

K

Adds the top 2 numbers on the stack. That's it.

Now how to push them on to the stack, I have no clue. I don't think it's possible.. cough @CᴏɴᴏʀO'Bʀɪᴇɴ cough

Rɪᴋᴇʀ

Posted 2016-07-02T00:40:45.547

Reputation: 7 410

Explanation soon to be coming. -- Riker Jul 3 '16 – MD XF – 2017-09-26T04:42:59.870

+1 for a Game of Life language. – HighlyRadioactive – 2019-09-27T05:29:21.620

4

Shakespeare Programming Language (SPL) , 137 135 bytes

Complete program, golfed:

.
A.
B.
Act I
Scene I
[Enter A and B]
A: Listen to your heart!
B: Listen to your heart! You are the sum of me and you. Open your heart! 

And a brief explanation:

----
.                                 <- Title, everything before the first 
                                     full stop is considered as the tittle and treated as a comment
----
A.                                <- Dramatis personae. Here are introduced the characters in the play.
                                     |Characters are treated as variables.   
B.                                <--
----
Act I                             <- Acts and scenes are used to divide a program into smaller
                                     chunks in order to be able to refer to them later.
                                     |
Scene I                           <--
----
[Enter A and B]                   <- Characters on stage in the current scene, which are the              
                                     variables the program will have access to.
----
A: Listen to your heart!          <- Line of code. All of them have the same structure
                                     Variable: code. In this case, the concrete sentence
                                    "Listen to your heart!" reads an input number and stores it
                                     on the character (variable) refered to.
B: Listen to your heart!          <- Same as above 
   You are the sum of me and you. <- Sum the values of itself and the caharacter (variable)
                                     refered to.
   Open your heart!               <- Output the value of the character (value) refered to.

I am not actualy sure this is the shortest it can go. Check the official page for more info.

Edit 1: Removed the : after Act I and Scene I as it seems that everything after the roman numeral is ignored, thus saving 2 bytes.

Ioannes

Posted 2016-07-02T00:40:45.547

Reputation: 595

6This is not valid. The characters have to be from Shakespeare's plays and the :s do have to be there. Also, you need a comma after each character's name for a description. – Oliver Ni – 2016-10-13T18:19:49.453

You should be testing your code on TIO. – Hello Goodbye – 2020-01-07T14:47:39.980

4

x86_32 machine code, 2 bytes

08048540 <add7>:
 8048540:   01 c8                   add    %ecx,%eax

Assuming the two values are already in the ecx and eax registers, performing the add instruction will add the values of the two registers and store the result in the destination register.

You can see the full program written in C and inline assembly here. Writing the wrapper in C makes it easier to provide inputs and do testing, but the actual add function can be reduced down to these two bytes.

davey

Posted 2016-07-02T00:40:45.547

Reputation: 321

3This isn't a function, just a snippet. You need a ret instruction as well (one byte). And that's assuming a custom calling convention where eax is used as an arg-passing register. (The Irvine32 asm teaching library does that, but no standard calling conventions for x86-32 or x86-64 do that, unlike on ARM where the return-value register r0 is also the first arg-passing register.) Custom calling conventions are fine in asm functions though, so you don't need to change it to 3 byte lea (%ecx, %edx), %eax + 1 byte ret for Microsoft __fastcall or gcc -mregparm. – Peter Cordes – 2017-12-17T19:20:34.027

1It's an interesting challenge for a stack-args calling convention, though. pop is only 1 byte, but esp-relative addressing modes need a SIB byte. So a caller-pops calling convention might pop %ecx (the return address), pop %eax / pop %edx / add %edx, %eax (2 bytes) / jmp *%ecx (2 bytes) = 7 bytes total. vs. mov 4(%esp), %eax (4B) / add 8(%esp), %eax (4B) / ret = 9 bytes, or 11 bytes for a caller-pops version of that using ret imm16, if I did that right. It's an extra 1 byte for the SIB with ESP as a base, and an extra 1 byte for the disp8 in each insn. – Peter Cordes – 2017-12-17T19:26:19.340

4

Wise, 12 bytes (non-competing)

Mistah Figgins has me beat here

[:??:?^?&<]|

I just made this language so I thought I would try the basics.

Try it online

Explanation

[   ...   ]      #Loop until our carry is zero
 :               #Duplicate the top
  ??             #Roll the top two to the bottom
    :            #Duplicate the top
     ?           #Roll to the bottom

At this point we have n m m n on the stack

      ^          #Xor n and m
       ?         #Roll that to the bottom
        &        #And n and m to create the carry over
         <       #Bitshift to the left
           |     #Remove the extra zero with an or

Post Rock Garf Hunter

Posted 2016-07-02T00:40:45.547

Reputation: 55 382

1[?~-!-~]| should work, and it is stack clean – MildlyMilquetoast – 2017-03-22T04:30:43.607

@MistahFiggins Nice answer. I like my answer as is because it uses cool bitwise properties do add and yours is sufficiently different so I would recommend making your own answer to the question. – Post Rock Garf Hunter – 2017-03-22T04:45:58.190

4

awk, 14 bytes

{print $1+$2}

I am not sure if this is acceptable because the arguments must be passed through a pipe using echo, or through the stdin stream in a file like so:

[user@localhost ~]$ echo '15 6' | awk -E add.awk
21
[user@localhost ~]$ echo '15 6' > numbers
[user@localhost ~]$ awk -E add.awk < numbers 
21

Permissible or not, I am excited to take my first swing at code golf!

Lledargo

Posted 2016-07-02T00:40:45.547

Reputation: 41

Welcome to PPCG! This is perfectly valid! – NoOneIsHere – 2016-10-27T18:19:46.390

Of course is allowed to take input through STDIN. :) The other awk solution works the same way, just using here-string syntax in the sample run. (Some of us are finding it more readable.) BTW, the space after print is not necessary.

– manatwork – 2016-10-27T18:23:07.970

3

Turing Machine Simulator, 342 bytes

0 _ * r 1
0 * * r *
1 _ * r *
1 * * * 2
2 0 _ r *
2 * * * 3
3 _ * l 4
3 * * r *
4 _ * * halt
4 0 9 l *
4 1 0 l 5
4 2 1 l 5
4 3 2 l 5
4 4 3 l 5
4 5 4 l 5
4 6 5 l 5
4 7 6 l 5
4 8 7 l 5
4 9 8 l 5
5 _ * l 6
5 * * l *
6 _ * l *
6 * * * 7
7 _ 1 r 0
7 0 1 r 0
7 1 2 r 0
7 2 3 r 0
7 3 4 r 0
7 4 5 r 0
7 5 6 r 0
7 6 7 r 0
7 7 8 r 0
7 8 9 r 0
7 9 0 l *

Try it!

Input: Two decimal integers. These can be given to the code in standard input, as arguments to the program or function, or as a list.

Ugh...

Erik the Outgolfer

Posted 2016-07-02T00:40:45.547

Reputation: 38 134

2Explanation, please? – user41805 – 2016-12-03T12:12:22.210

3

Vim, 5 bytes

DJ@"<C-a>

Note that <C-a> is one byte: 0x01, which is an unprintable character.

Since V is mostly backwards compatible, you can Try it online!

Explanation:

D           " Delete this line. 
            " By default this will save it into the unnamed register (@")
 J          " Get rid of this empty line
  @"        " Run the unnamed register as if it was typed.
            " Since it's a number, it will provide a count to the next command
    <C-a>   " Increment the next number on this line

James

Posted 2016-07-02T00:40:45.547

Reputation: 54 537

3

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.

Martin Ender

Posted 2016-07-02T00:40:45.547

Reputation: 184 808

3

R, 3 bytes

"+"

or

sum

"+" can be called as a function like so: "+"(a,b) because the R interpreter will interpret it (with the parentheses) as the primitive addition function .Primitive("+"). Alternatively, sum will add arbitrary arguments. These are both functions.

Try it online!

Giuseppe

Posted 2016-07-02T00:40:45.547

Reputation: 21 077

3

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!

Post Rock Garf Hunter

Posted 2016-07-02T00:40:45.547

Reputation: 55 382

So the IP can spawn at any random position on the top row and left column of the playing field? – MD XF – 2017-09-26T04:08:53.947

@MDXF The ip can spawn anywhere including the top row and left column. – Post Rock Garf Hunter – 2017-09-26T04:15:29.327

So what happens if the location starts on @? – caird coinheringaahing – 2017-10-31T21:48:29.413

@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 @. – Post Rock Garf Hunter – 2017-10-31T22:52:14.920

@WheatWizard Ah, didn't know about the % rule. Interesting language! – caird coinheringaahing – 2017-10-31T23:11:04.840

@cairdcoinheringaahing The % is a very important feature, without it as you might have noticed, every program would have a small chance of immediately exiting. – Post Rock Garf Hunter – 2017-11-01T04:02:47.383

3

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

FireCubez

Posted 2016-07-02T00:40:45.547

Reputation: 857

3

Alchemist, 253 211 205 bytes

_->u+v+2r
u+r->In_a+In_x
v+r->In_b+In_y
a+b->Out_"-"
0_+0r+0d+0a+0b->d
0d+0a+x+b+y->b
0r+0d+a+0b+0y->d+Out_"-"
0r+0d+0b+a+0x->d
a+x+0b+y->a
0r+0d+0a+b+0x->d+Out_"-"
0r+0d+0a+b+0y->d
d+x->d+y
d+y->d+Out_"1"

Since Alchemist can't handle negative numbers (there can't be a negative amount of atoms) this takes 4 inputs on stdin in this order:

  • sign of x (0 -> + and 1 -> -)
  • the number x itself
  • sign of y (0 -> + and 1 -> -)
  • the number y itself

Output is in unary, try it online!

(for your convenience, here is a wrapper, converting inputs and returning decimal outputs)

Explanation & ungolfed

Since Alchemist applies the rules non-deterministically we need a lot of 0-rules.. Initially there is only one _ atom, so we use that to read the inputs:

_->u+v+2r
u+r->In_a+In_x
v+r->In_b+In_y

The following rules can't be applied because they all require 0r, now we have a, b as the signs of x and y respectively.

# Case -x -y: we output the sign and remove a,b
# therefore we will handle them the same as +x +y
0_+0r+0d+a+b->Out_"-"        #: 0_+0r+0d ⇐ a+b

# Case +x +y: doesn't need anything done
0_+0r+0d+0a+0b->d

# Case +x -y:
## remove one atom each
0_+0r+0d+0a+x+b+y->b         #: 0_+0r ⇐ x+b
## if we had |y| > x: output sign and be done
0_+0r+0d+a+0b+0y->d+Out_"-"  #: 0_ ⇐ 0r+a
## else: be done
0_+0r+0d+0b+a+0x->d          #: 0_ ⇐ 0r+a

# Case -x +y is symmetric to the +x -y case:
0_+0r+0d+a+x+0b+y->a         #: 0_+0r+0d ⇐ a+y
0_+0r+0d+0a+b+0x->d+Out_"-"  #: 0_ ⇐ 0r+b
0_+0r+0d+0a+b+0y->d          #: 0_ ⇐ 0r+b

# All computations are done and we can output in unary:
0_+d+x->d+Out_"1"            #: 0_ ⇐ d
0_+d+y->d+Out_"1"            #: 0_ ⇐ d

To the right of some rules I marked some golfs with #: y ⇐ x which should read as: "The conditions x imply y at this stage and thus we can remove it without changing the determinism"

ბიმო

Posted 2016-07-02T00:40:45.547

Reputation: 15 345

1

ew. better output pls

– ASCII-only – 2019-01-29T10:06:40.453

ew. rules are rearranged based on alphabetical order so input is in wrong order if you try to combine them – ASCII-only – 2019-01-29T10:09:21.423

wip – ASCII-only – 2019-01-29T10:10:25.737

154? – ASCII-only – 2019-01-29T10:35:15.653

135? – ASCII-only – 2019-01-29T10:52:36.700

Almost certainly still golfable but I'm moving on for now – ASCII-only – 2019-01-29T10:59:24.653

131 – ASCII-only – 2019-01-30T08:57:09.757

3

Intel 8080 machine code, Altair 8800, 22 bytes

This will add two integers of nearly any size (16, 32, 64-bit, etc) using an Intel 8080 8-bit CPU (c. 1974). This is implemented as a full program, running on a MITS Altair 8800.

Code listing and programming instructions:

Step    Switches 0-7    Control Switch  Instruction Comment
1                       RESET
2       00 001 110      DEPOSIT         MVI  C, 2   ; loop counter set to word size
3       00 000 010      DEPOSIT NEXT                ; value is 2
4       00 010 001      "               LXI  D, 16H ; load address of first term into E:D
5       00 010 110      "                           ; at memory address 16H
6       00 000 000      "          
7       00 100 001      "               LXI  H, 18H ; load address of second term into H:L
8       00 011 000      "                           ; memory address 16H + word size = 18H
9       00 000 000      "          
10      10 101 111      "               XRA  A      ; clear accumulator
11      00 011 010      "               LOOP:LDAX D ; load [E:D] into A
12      10 001 110      "               ADC  M      ; add [H:L] + previous carry, to A
13      00 010 010      "               STAX D      ; store result in A to [E:D]
14      00 001 101      "               DCR  C      ; decrement loop counter
15      11 001 010      "               JZ   DONE   ; if counter is zero, end addition
16      00 010 101      "                           ; jump to step 23
17      00 000 000      "       
18      00 010 011      "               INX  D      ; first term next byte
19      00 100 011      "               INX  H      ; second term next byte
20      11 000 011      "               JMP  LOOP   ; restart loop
21      00 001 001      "                           ; jump to step 11
22      00 000 000      "           
23      01 110 110      "               DONE:HLT    ; halt CPU
24      00 001 110      "                           ; Term 1 low byte (14) 
25      00 000 000      "                           ; Term 1 high byte (0)
26      00 001 111      "                           ; Term 2 low byte (15)         
27      00 000 000      "                           ; Term 2 high byte (0)    
31                      RESET                       ; Reset program counter to beginning
32                      RUN
33                      STOP            
34      00 010 110      EXAMINE                     ; low byte of output displayed on D7-D0
35                      EXAMINE NEXT                ; high byte of output displayed on D7-D0

Try it online!

If entered correctly, RAM contents should look like:

0000    0e 02 11 16 00 21 18 00 af 1a 8e 12 0d ca 15 00 
0010    13 23 c3 09 00 76 0e 00 0f 00

I/O:

The above program adds two 16-bit integers, located in memory address 16H and 18H. This could accept larger integers, for example 32-bit integers by changing steps 3 and 8 to values 4 and 20H respectively, and then input would be in 16H and 20H. Numbers are represented in memory as little endian.

Output is displayed on lights D7-D0.

Example: 14 + 15 = 29 = 00 011 101

enter image description here

Example: 1234 + 4321 = 5555 = 00 010 101, 10 110 011

enter image description here

enter image description here

640KB

Posted 2016-07-02T00:40:45.547

Reputation: 7 149

3

05AB1E, 1 byte

Code:

+

Try it online!.

Adnan

Posted 2016-07-02T00:40:45.547

Reputation: 41 965

3

Golfscript, 9 2 bytes

~+

~ casts to int[], and + adds.

NoOneIsHere

Posted 2016-07-02T00:40:45.547

Reputation: 1 916

Just do this. – Leaky Nun – 2016-07-02T02:23:35.687

@LeakyNun Input must be in the form m n not m<newline>n. – NoOneIsHere – 2016-07-02T02:24:37.693

It is the same. – Leaky Nun – 2016-07-02T02:26:11.840

@NoOneIsHere It can be any whitespace character. – dkudriavtsev – 2016-07-02T03:25:01.100

3

Java, 31 bytes

int A(int b,int B){return b+B;}

Making the above snippet code compilable costs 9 bytes, resulting in a 40-byte program:

class a{int A(int b,int B){return b+B;}}

The "equivalent" monolithic program that can also handle numbers between 231 and 263-1 (inclusive) is 98 bytes long:

interface a{static void main(String[]A){System.out.print(Long.valueOf(A[0])+Long.valueOf(A[1]));}}

Java (lambda expression), 11 bytes

(a,b)->a+b;

This is a java.util.function.BinaryOperator<Integer>. It can also be a java.util.function.BinaryOperator<Long> if you have to add larger numbers.

user8397947

Posted 2016-07-02T00:40:45.547

Reputation: 1 242

1You could make this a lambda function and make it a lot shorter: (long a,long b)->a+b;. – Mego – 2016-07-02T03:31:03.130

@Mego Well, I actually take pride in golfing standalone programs that compile without any modification(s). – user8397947 – 2016-07-02T03:34:50.390

10Not golfing your code as much as possible is anathema to the point of code golf. – Mego – 2016-07-02T03:35:36.510

adding two numbers in java takes 40 bytes??? – downrep_nation – 2016-07-02T15:40:10.920

@downrep_nation Yes! – user8397947 – 2016-07-02T15:42:20.700

*a wild downvote appears* But why? – user8397947 – 2016-07-03T18:53:43.963

This is still not as golfed as it could be - see my first comment. – Mego – 2016-07-04T02:25:22.377

@Mego That's a snippet. – user8397947 – 2016-07-04T02:30:32.537

2No, it's a lambda function. – Mego – 2016-07-04T02:30:49.387

@Mego Lambda functions don't compile without some additional boilerplate that destroys the entire point of using a lambda by making the program longer than the equivalent program that uses plain old methods. Such boilerplate looks like this: class a{java.util.function.BinaryOperator<Long>A=(b,B)->b+B;} – user8397947 – 2016-07-04T02:44:13.077

3@dorukayhan The point is, it's a function submission. We allow those. You don't need an enclosing class, and you don't need to worry about the necessary boilerplate for capturing the function. – Mego – 2016-07-04T03:07:16.447

1@dorukayhan If you look closely at the question, it states that standalone functions are allowed. – dkudriavtsev – 2016-07-04T07:58:14.710

2It's too bad this got downvoted. This is the shortest java answer I've ever seen. – James – 2016-07-17T21:43:27.293

Did I just turn the score of this answer around by doing nothing more than adding a super-short solution? – user8397947 – 2016-07-18T01:23:12.807

Your full program can be golfed a bit more: both Long.valueOf(...) can be replaced with new Long(...). – Kevin Cruijssen – 2017-01-11T08:46:51.967

You don't need the parenthesis around a,b-> – FlipTack – 2017-01-23T21:51:11.557

1Curry to save a byte: a->b->. And no need for the semicolon; it's an expression. – Jakob – 2017-09-04T04:10:08.377

3

Labyrinth, 5 bytes

??+!@

Try it online!

Very straightforward: read input, read input, add, print, terminate.

Martin Ender

Posted 2016-07-02T00:40:45.547

Reputation: 184 808

3

Fishing, 22 bytes

v+CCCCCCCC
  In{In}aP

Explained

Sets casting direction down and casting length to 1.
Read input to the first 2 cells on the tape and convert to numbers.
Add the first 2 cells together and print.

Emigna

Posted 2016-07-02T00:40:45.547

Reputation: 50 798

3

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

rael_kid

Posted 2016-07-02T00:40:45.547

Reputation: 341

3

C++ – 56 bytes

Should work on all unsigned integer types:

template<typename U>U f(U a,U b){return b?f(++a,--b):a;}

This is multiplication in the same style:

template<typename U>U g(U a,U b){return b>1?f(g(a,--b),a):(b?a:0);}

Finally exponentiation:

template<typename U>U h(U a,U b){return b>1?g(h(a,--b),a):(b?a:1);}

To test:

#include <iostream>

template<typename U>U f(U a,U b){return b?f(++a,--b):a;}
template<typename U>U g(U a,U b){return b>1?f(g(a,--b),a):(b?a:0);}
template<typename U>U h(U a,U b){return b>1?g(h(a,--b),a):(b?a:1);}

int main()
{
    std::cout << f(3, 4) << std::endl;
    std::cout << g(3, 4) << std::endl;
    std::cout << h(3, 4) << std::endl;
    return 0;
}

Output:

7
12
81

user15259

Posted 2016-07-02T00:40:45.547

Reputation:

2Dude, this is code golf. No need for templates, or the needlessly complicated addition, or even using typename instead of class... – proud haskeller – 2016-07-05T16:36:06.247

5OP indicated he was "interested to see how it can be implemented". Thought it was an interesting approach to express addition, multiplication and even exponentiation as increment operations. – None – 2016-07-05T17:21:11.240

3

Hexagony, 9 bytes

?{?+@/!'/

Embiggened:

   ? { ?
  + @ / !
 ' / . . .
  . . . .
   . . .

Try it online!

Interestingly, this is only 2 bytes shorter than (what I think is) the most basic version, which is:

   ? { ?
  . . . .
 ' + ! @ .
  . . . .
   . . .

This requires 7 commands, of which one (?, which reads a number from STDIN). Now, as 7 is the 2nd centered hexagonal number, it might be able to fit inside a hexagon of side length 2, if you can use a single flow control character and reuse the ?. I've not been able to figure that out yet though :o(

Sok

Posted 2016-07-02T00:40:45.547

Reputation: 5 592

3

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.

Robert Benson

Posted 2016-07-02T00:40:45.547

Reputation: 1 339

1Wouldn't you still have to run it as sum <<< "98.342 77.123", or echo | sum? – Peter Cordes – 2017-12-17T19:46:55.317

You are correct. It would work better if the data were placed in a file, or as you suggested. – Robert Benson – 2017-12-20T19:56:03.540

3

Brainfuck, 224 bytes

+[-->++++++[-<------>]+>>,----------]<,[<+++++[->-------
-<]+[<<<]>>[-]>[>[-<<<+<[-]+>>>>]>>]<<,]<-<<<[>[->+<]>[-
<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<[-]<<+<<[-
]+>>>>>[-<+>]]]]]]]]]]]<<<<<]>>>[+++++[->++++++++<]>.>>]

Try it online!

Arbitrary precision. Input is taken newline separated, null terminated.

primo

Posted 2016-07-02T00:40:45.547

Reputation: 30 891

3

Perl 6, 3 bytes

*+*

A lambda that takes two arguments and returns their sum.

smls

Posted 2016-07-02T00:40:45.547

Reputation: 4 352

3

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));
}

Shaun Wild

Posted 2016-07-02T00:40:45.547

Reputation: 2 329

You can save 1 byte: a->b->a+b; – TuxCrafting – 2016-10-08T11:09:17.523

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). – Olivier Grégoire – 2018-06-03T07:41:22.770

3

C, 19 bytes

f(a,b){return a+b;}

RosLuP

Posted 2016-07-02T00:40:45.547

Reputation: 3 036

17 bytes: f(a,b){b+=a;a=b;} – Johan du Toit – 2017-12-07T14:55:46.593

1@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) – RosLuP – 2017-12-07T18:40:37.320

@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. – Peter Cordes – 2017-12-17T19:29:03.170

3

sed, 275 bytes

s/[1-9]/0&/g
s/[5-9]/4&/g
s/[89]/4&/g
s/[2367]/xx&/g
s/[13579]/x/g
s/4/xxxx/g
s/[1-8]//g
s/$/ /
:a
s/\(.*\)0\(x*\) \(.*\)0\(x*\) /\1 \3 0\2\4/
ta
s/  *//g
:c
s/0xxxxxxxxxx/x0/g
tc
s/0x/-x/g
s/xx/2/g
y/x/1/
s/22/4/g
s/44/8/g
s/81/9/g
s/21/3/g
s/42/6/g
s/43/7/g
s/41/5/g
s/-//g

Takes 2 space-separated decimal integers on standard input; prints their sum to standard output

Explanation

We represent each input in unary-coded decimal, using x as our digit, and 0 as separator. For example, 42 is written 0xxxx0xx.

#!/bin/sed -f

# Convert to unary decimal
s/[1-9]/0&/g
s/[5-9]/4&/g
s/[89]/4&/g
s/[2367]/xx&/g
s/[13579]/x/g
s/4/xxxx/g
s/[1-8]//g

# Append space to separate second input from output
s/$/ /
# Consume the smallest of each digit from input, and push
# the sum to output
:add
s/\(.*\)0\(x*\) \(.*\)0\(x*\) /\1 \3 0\2\4/
tadd

# Everything is now accumulated in output; remove the spaces
s/  *//g
# Add carry to the next position
:carry
s/0xxxxxxxxxx/x0/g
tcarry

# Back to decimal
s/0x/-x/g
s/xx/2/g
y/x/1/
s/22/4/g
s/44/8/g
s/81/9/g
s/21/3/g
s/42/6/g
s/43/7/g
s/41/5/g
s/-//g

The extension to support decimal fractions is left as an exercise for the reader.

Toby Speight

Posted 2016-07-02T00:40:45.547

Reputation: 5 058

Unfortunately, this doesn't seem to work with negative numbers. – Riley – 2016-10-10T21:32:04.887

Also, if you're okay with using GNU sed, labels can be blank. :;b is an infinite loop. Using -r you don't need the \ in \( and \). And you might be able to get rid of the label :c entirely by jumping to :a everytime, but I'm not sure. – Riley – 2016-10-10T21:36:01.700

@Riley - I overlooked that the numbers might be negative (I was reusing something I already had). I'll have a look at implementing that when I can. As for GNU sed; yes, I do often use the GNU implementation, but for this answer I chose to go the POSIX route. – Toby Speight – 2016-10-11T07:50:09.993

2

Japt, 1 byte

x

Here is a non-1 byte solution

U+V

Try it online!

Oliver

Posted 2016-07-02T00:40:45.547

Reputation: 7 160

1I read that as × at first and got really confused :P – ETHproductions – 2017-01-10T20:07:15.557

@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 – Oliver – 2017-01-10T20:20:39.797

2

Kitanai, 15 bytes

add input input

Pretty straightforward :)

Sygmei

Posted 2016-07-02T00:40:45.547

Reputation: 1 137

2

√ å ı ¥ ® Ï Ø ¿ , 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

caird coinheringaahing

Posted 2016-07-02T00:40:45.547

Reputation: 13 702

2

Cubically, 10 8 bytes

$+7$+7%6

Try it online!

Cubically is a language relatively early in development. Its most unique feature is that its primary memory takes the form of a virtual Rubik's Cube with the colors replaced by numbers from 0 to 5. This Rubik's Cube cannot be written to, and manipulation of it is done only through rotation commands, with only a single "notepad" memory space which supports more traditional manipulation. All operations consist of a non-digit character, followed by any number of digits representing the memory location to use: 0-5 for the face centered on the chosen number, 6 for the notepad, and 7 for the "input buffer".

All that said, this program uses none of the language's unique features and instead does all operations in the notepad and the input buffer which was added today to finally qualify for this challenge since before now there simply was no input. Explanation:

                  Notepad defaults to 0
$               Read an integer from STDIN
 +7             Add the value in [7] (input buffer) to the notepad
   $            Read an integer from STDIN
    +7          Add the value in [7] (input buffer) to the notepad
      %6        Output the value in [6] (notepad) to STDOUT

The language was updated and now allows the $ command to be called without an argument, saving 2 bytes by not including unused characters

Look forward to more Cubically answers as advanced features are added such as looping and branching!

Kamil Drakari

Posted 2016-07-02T00:40:45.547

Reputation: 3 461

2

JavaScript (Node.js), 28 bytes

f=(a,b)=>b?f(a^b,(a&b)<<1):a

Try it online!

Not for winning rather just for fun. Definitely not the shortest but my fav.

user79855

Posted 2016-07-02T00:40:45.547

Reputation:

2

Java (JDK 10), 9 bytes

Long::sum

Try it online!

Olivier Grégoire

Posted 2016-07-02T00:40:45.547

Reputation: 10 647

2

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

Jo King

Posted 2016-07-02T00:40:45.547

Reputation: 38 234

2

Help, Wardoq!, 1 byte

A

Try it online!

Note: Due to technical limitations, this interpreter takes code as the first line, and input as every line after.

VFDan

Posted 2016-07-02T00:40:45.547

Reputation: 173

2

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)

pppery

Posted 2016-07-02T00:40:45.547

Reputation: 3 987

2

Microsoft PowerPoint (macro-free), 176 animations, 73 shapes on main slide

(Numbers estimated from XML explorer)

I made a 2-bit adder with carry input and carry output. Numbers represented in binary. Get the PPTX here. Directions are included in the presentation.

I'm thinking this is very golf-able, but it's a fun proof of concept anyway. Obviously, this can be extended to more bits, but frankly, programming in PowerPoint is extremely tedious with its current UI, so I'm going to move on to other things.

How it works

When the presentation starts, it is in input mode. The switches toggle a motion path animation back and forth to indicate 1 or 0.

When the Run button is clicked, it steps through each of the input bits and uses the K-maps for the carry and result bits. If there is a value dependent on the result (such as the carry bit over the second column), it uncovers a button that allows the machine to read that bit. When the final digit is clicked, the machine enters a halt state, displaying the final result in the bottom row.

Calculuswhiz

Posted 2016-07-02T00:40:45.547

Reputation: 193

2

Minkolang 0.15, 5 bytes

nn+N.

Try it here.

Explanation

nn       Take two numbers from input
  +      Add
   N.    Output as number and stop.

El'endia Starman

Posted 2016-07-02T00:40:45.547

Reputation: 14 504

2

Silicon, 3 bytes

II+

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

m654

Posted 2016-07-02T00:40:45.547

Reputation: 765

2

PHP 4.1, 9 bytes

This assumes a standard php.ini file, with short_open_tag=On and register_globals=On (default in PHP 4.1).

<?=$A+$B;

This assumes that you are acessing the file through a webserver (like Apache).
The keys A and B contain the numbers you want to sum.
An example: http://localhost/sum.php?A=5&B=16. (POST, GET, SESSION and COOKIE can be used too).

Ismael Miguel

Posted 2016-07-02T00:40:45.547

Reputation: 6 797

2

Jolf, 1 byte

Interpreter.

u

Take sum of list.

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

Conor O'Brien

Posted 2016-07-02T00:40:45.547

Reputation: 36 228

2

cubix, 6 bytes

OI\@+I

Try it here!

This maps onto a cube with edge length one.

  O
I \ @ +
  I

Much the same as other stack based answers, push input to the stack twice, add, output and terminate.
Operations are

  • I, input number
  • \, reflect down
  • I, input number
  • +, add top two of stack
  • O, output number
  • \, reflect to the right
  • @, terminate

The following will also work

II/@+O

Mapping to

  I
I / @ +
  O

MickyT

Posted 2016-07-02T00:40:45.547

Reputation: 11 735

2

Sesos, 5 bytes (non-competing)

0000000: d605ba 8f07                                       .....

Try it online!

set numin
set numout
get
fwd 1
get
jmp
sub 1
rwd 1
add 1
fwd 1
jnz
rwd 1
put

acrolith

Posted 2016-07-02T00:40:45.547

Reputation: 3 728

I would recommend using jmp instead of nop to make it work for 0-Infinity instead of 1-Infinity. – Erik the Outgolfer – 2016-10-05T16:58:03.560

@EriktheGolfer Done. – acrolith – 2016-10-05T22:27:49.673

2

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())

Frédéric

Posted 2016-07-02T00:40:45.547

Reputation: 2 059

2

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

Copper

Posted 2016-07-02T00:40:45.547

Reputation: 3 684

2

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.)

Connor D

Posted 2016-07-02T00:40:45.547

Reputation: 81

2

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.

– isaacg – 2016-10-06T05:28:16.317

2

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

TuxCrafting

Posted 2016-07-02T00:40:45.547

Reputation: 4 547

2

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

Pete Arden

Posted 2016-07-02T00:40:45.547

Reputation: 1 151

2

Charcoal, 4 2 bytes

I⁺

Try it online!

Explanation

I Cast to string
 ⁺ Add
   (implicit) Input number
   (implicit) Input number

ASCII-only

Posted 2016-07-02T00:40:45.547

Reputation: 4 687

2

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)

Niclas M

Posted 2016-07-02T00:40:45.547

Reputation: 61

1

Python 3, 22 bytes

lambda a,b:a+b

Trivial answer for a kind of trivial question.

python-b5

Posted 2016-07-02T00:40:45.547

Reputation: 89

1

You could golf this to lambda a,b:a+b. Although there's already a 3-byte python solution here.

– FlipTack – 2016-12-24T21:43:47.537

1

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)

TrojanByAccident

Posted 2016-07-02T00:40:45.547

Reputation: 300

1

Euphoria, 64 bytes

Code:

include get.e
print(1,prompt_number("",{})+prompt_number("",{}))

P. Ktinos

Posted 2016-07-02T00:40:45.547

Reputation: 2 742

1

TI-Basic, 2 bytes

Very straightforward.

sum(Ans

Timtech

Posted 2016-07-02T00:40:45.547

Reputation: 12 038

1

tcl, 10

expr $a+$b

If you have namespace path tcl::mathop you can do it shorter for every arithmetic operation:

tcl, 7

+ $a $b

test case on: http://rextester.com/live/FLFPTH24568

sergiol

Posted 2016-07-02T00:40:45.547

Reputation: 3 055

1

Whirl, 32 bytes

01100100001100011110001000111100

Try it online!

Explanation

Whirl has two "rings" of operations, one for control and I/O operations and the other for math operations. The 1 command rotates the current operation ring while the 0 command switches direction of the rotation. Two 0s in a row run the current operation and switch to the other ring.

01100    Read an integer from stdin and store it at the memory pointer
100      Load that value into the math ring data storage
00       Read an integer from stdin and store it at the memory pointer
1100     Add the the values under the memory pointer to the math ring data storage
0111100  Set the control ring data storage to 1
0100     Save the math ring data storage to the memory at the memory pointer
0111100  Print the result from the memory at the memory pointer

0 '

Posted 2016-07-02T00:40:45.547

Reputation: 3 439

1

V, 2 bytes

À

Try it online!

You can't see it, but after the À there is a control-a character (ASCII 0x01).

This answer is nice because it shows one of the nice things about V: Numeric input is more convenient. Note how one input is an argument and the other is in the "input" field. This is an allowed input method, and it saves bytes because we want to run something n times, in this case the increment command or ctrl-a.

À           " Arg1 times:
 <C-a>      "   Increment the next number found on this line

James

Posted 2016-07-02T00:40:45.547

Reputation: 54 537

1

SmileBASIC, 13 bytes

INPUT A,B?A+B

12Me21

Posted 2016-07-02T00:40:45.547

Reputation: 6 110

“Input: Two decimal integers. These can be given to the code in standard input, as arguments to the program or function, or as a list.” Sure your code handles input? – manatwork – 2017-01-24T08:43:24.927

Ok, I fixed it. – 12Me21 – 2017-01-24T16:19:44.650

1

Taxi, 418 bytes

Go to Post Office:w 1 l 1 r 1 l.Pickup a passenger going to The Babelfishery.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:w 1 l 1 r.Pickup a passenger going to Addition Alley.Pickup a passenger going to Addition Alley.Go to Addition Alley:e 5 l 1 l.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:w 1 r 1 r.Pickup a passenger going to Post Office.Go to Post Office:e 1 l 1 r.

Try it online!

Erik the Outgolfer

Posted 2016-07-02T00:40:45.547

Reputation: 38 134

1

Wise, 9 bytes

[?~-!-~]|

Try it Online!

Takes 2 numbers in, A, and B.

             Implicit input
[ .... ]     While the top (B) != 0, repeat:
 ?           Move B to the bottom
  ~-         Add 1 to the top (A)
    !        Move B back to the top
     -~      Subtract 1 from the top (B)

        |    Gets rid of the 0 on top by ORing the top 2
             Implicit output

It boils down to "Add 1 to A, B times."

Less cool than the other Wise answer, but also shorter.

MildlyMilquetoast

Posted 2016-07-02T00:40:45.547

Reputation: 2 907

1

Sinclair ZX80 BASIC (4K ROM)

The usual rules about the ZX80 and its 16 bit signed integer range apply here. Anything out of this range will not add. And because PRINT A+B is too easy, I came up with two solutions:

Method 1 ~64 bytes:

This assumes that you're adding a positive integer to the first number entered:

 1 INPUT A
 2 INPUT B
 3 IF B=0 THEN GO TO 7
 4 FOR B=B/B TO ABS(B)
 5 LET A=A+1
 6 NEXT B
 7 PRINT A

Method 2 ~24 bytes

A much simpler solution, where you are adding two -/+ integers together, simply do this:

 1 INPUT A
 2 INPUT B
 3 PRINT A+B

Both of these listings are likely to work on all variants of 8-bit BASIC, although would not be optimised on most of them.

Shaun Bebbers

Posted 2016-07-02T00:40:45.547

Reputation: 1 814

There are no such things as functions on a Sinclair ZX80 (as far as I know anyway) so both solutions are complete symbolic listings. – Shaun Bebbers – 2017-03-28T20:55:59.160

1

totallyhuman

Posted 2016-07-02T00:40:45.547

Reputation: 15 378

1

Triangular, 6 bytes

$.$%+<

Try it online!

Formats into this triangle:

  $
 . $
% + <

Without directionals or no-ops, the above turns into this: $$+%

Triangular uses postfix notation.

  • $ - read input as integer
  • + - add
  • % - print as integer

MD XF

Posted 2016-07-02T00:40:45.547

Reputation: 11 605

1

,,,, 1 byte

+

Body must be at least 30 characters; you entered 14.

totallyhuman

Posted 2016-07-02T00:40:45.547

Reputation: 15 378

1

Commentator, 4 bytes

////

Outputs by char code. If this isn't allowed, a 6 byte solution is

////*/

which outputs by numerical value.

caird coinheringaahing

Posted 2016-07-02T00:40:45.547

Reputation: 13 702

1

Little Man Computer, 23 bytes (source)

INP
STA 6
INP
ADD 6
OUT

With HLT, 27 bytes (source)

INP
STA 6
INP
ADD 6
OUT
HLT

Online Emulator (Flash)

GarethPW

Posted 2016-07-02T00:40:45.547

Reputation: 1 119

1

Bitwise, 89 bytes

IN 1 &1
IN 2 &1
LABEL &1
AND 1 2 *1
XOR 1 2 *2
SL *1 &1 1
MOV 2 *2 &1
JMP @1 *1
OUT *2 -1

Input and output are raw byte values as that is the only method of I/O for this language. Allowed per this consensus. Try it online!

Ungolfed, written properly, and commented:

IN 1 &1 -1       read a character into r1 if l1 truthy, discarding result
IN 2 &1 -1       read a character into r2
LABEL &1         create label 1 here
AND 1 2 *1       set fr1 to r1 & r2 where & represents bitwise AND
XOR 1 2 *2       set fr2 to r1 ^ r2 where ^ represents bitwise exclusive or
SL *1 &1 1       set r1 to fr1 << 1 where << represents bitwise left shift
MOV 2 *2 &1      move fr2 into r2 if &1 truthy
JMP @1 *1        jump to label 1 if fr1 truthy
OUT *2 &1 -1     print frame register 2 if l1 truthy, discarding result

Note that fr is short for frame register, r is short for register and l is short for literal.

MD XF

Posted 2016-07-02T00:40:45.547

Reputation: 11 605

1

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.

KSmarts

Posted 2016-07-02T00:40:45.547

Reputation: 1 830

1

NotQuiteThere, 8 bytes

0-- 0- 0

Try it online!

Given that one of the aims of this languages was to be unable to perform addition, I think I failed.

How it works

       # Implicit input; 10 and 20
0      # Push 0;   STACK = [10 20 0]
 -     # Subtract; STACK = [10 -20]
  -    # Subtract; STACK = [-30]
   0   # Push 0;   STACK = [-30 0]
    -  # Subtract; STACK = [30]
     0 # Push 0;   STACK = [30 0]
       # Output 30;

caird coinheringaahing

Posted 2016-07-02T00:40:45.547

Reputation: 13 702

1

Perl 5, 7 bytes

6 bytes code + 1 for -p.

$_+=<>

Try it online! (-l added for readability.)

Dom Hastings

Posted 2016-07-02T00:40:45.547

Reputation: 16 415

1

Verbosity, 388 bytes

Include<Input>
Include<Output>
Include<Integer>
Include<MetaFunctions>
Input:DefineVariable<i; 0>
Output:DefineVariable<o; 0>
Integer:DefineVariable<f; Input:ReadEvaluatedLineFromInput<i>>
Integer:DefineVariable<s; Input:ReadEvaluatedLineFromInput<i>>
Integer:DefineVariable<r; Integer:Sum<f; s>>
Output:DisplayAsText<o; r>
DefineMain<> [
MetaFunctions:ExecuteScript<MetaFunctions@FILE>
]

Try it online!

Outputs as Integer<result> (the natural representation of integers in Verbosity)

Ungolfed

Include<Input>
Include<Output>
Include<Integer>
Include<MetaFunctions>

Input:DefineVariable<in; 0>
Output:DefineVariable<out; 0>

Integer:DefineVariable<first; Input:ReadEvaluatedLineFromInput<in>>
Integer:DefineVariable<second; Input:ReadEvaluatedLineFromInput<in>>

Integer:DefineVariable<result; Integer:Sum<first; second>>

Output:DisplayAsText<out; result>

DefineMain<> [
	MetaFunctions:ExecuteScript<MetaFunctions@FILE>
]

Try it online!

caird coinheringaahing

Posted 2016-07-02T00:40:45.547

Reputation: 13 702

1

Wumpus, 5 bytes

II+O@

Try it online!

Explanation

Straight-forward and boring:

I   Read the first integer.
I   Read the second integer.
+   Add them.
O   Output the result.
@   Terminate the program.

Martin Ender

Posted 2016-07-02T00:40:45.547

Reputation: 184 808

1

Forked, 5 bytes

$$+%&

Try it online!

  • $$ - read two integers
  • + - add top two stack values
  • % - print top of stack as integer
  • & - "terminate", prevents the IP from wrapping

MD XF

Posted 2016-07-02T00:40:45.547

Reputation: 11 605

1

Momema, 9 bytes

-8+*-8*-8

Try it online!

Momema uses prefix syntax, and assignment statements are implicit (simply writing two expressions ab acts as *a = b;), so this program looks like this:

*(-8) = *(-8) + *(-8)

The cell -8 in Momema is memory-mapped for numeric I/O. Reading from it causes input, and writing to it causes output.

print_num(read_num() + read_num())

Esolanging Fruit

Posted 2016-07-02T00:40:45.547

Reputation: 13 542

1

Perl6, 3

Standalone function:

*+*

Complete program (19 bytes):

say [+] slurp.words

bb94

Posted 2016-07-02T00:40:45.547

Reputation: 1 831

1

Whitespace, 36 bytes

[S S S N
_Push_0][S N
S _Duplicate][T N
T   T   _Read_STDIN_as_integer][T   T   T   _Retrieve][S S S N
_Push_0][S N
S _Duplicate][T N
T   T   _Read_STDIN_as_integer][T   T   T   _Retrieve][T    S S S _Add][T   N
S T _Print_as_integer]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (with raw spaces, tabs, and newlines only).

Explanation:

When a number is read from STDIN it stores it in the heap-address specified at the top of the stack, and then the Retrieve function can be used to get it later on. So to read a number from STDIN you'll need the following sub-steps:

  1. Put a number on the stack:
    • S at the start: Enable Stack Manipulation
    • S: Push what follows as number to the top of the stack
    • S/T: Positive or negative number
    • Some S and/or T followed by a N: Number as binary, where S=0 and T=1.
  2. Duplicate this number:
    • S at the start: Enable Stack Manipulation
    • NS: Duplicate the top value on the stack
  3. Read a number from STDIN, and store it in the heap-address specified at the top of the stack:
    • TN at the start: Enable I/O
    • TT: Read a number, and place it in the heap specified at the top of the stack
  4. Retrieve this number from the heap
    • TT at the start: Enable Heap Access
    • T: Retrieve a value from the heap with the given heap-address at the top of the stack

So here is every step of the full program above:

Command    Explanation              Stack      Heap     STDIN    STDOUT    STDERR

SSSN       Push 0                   [0]        {}                
SNS        Duplicate top (0)        [0,0]      {}                
TNTT       Read STDIN as integer    [0]        {0:-3}   -3        
TTT        Retrieve heap (at 0)     [-3]       {0:-3}                
SSSN       Push 0                   [-3,0]     {0:-3}                
SNS        Duplicate top (0)        [-3,0,0]   {0:-3}                
TNTT       Read STDIN as integer    [-3,0]     {0:5}    5        
TTT        Retrieve heap (at 0)     [-3,5]     {0:5}                
TSSS       Add top two              [2]        {0:5}                
TNST       Print top as integer     []         {0:5}            2
                                                                           Exit with error

Unfortunately the heap-address cannot be negative, otherwise the second SSSN (Push 0) could have been golfed to SNS (duplicate first STDIN input as heap-address).

Kevin Cruijssen

Posted 2016-07-02T00:40:45.547

Reputation: 67 575

1

Pain-Flak, 6 bytes

)}{}{(

Try it online!

Pain-Flak is Brain-Flaks evil twin. When translated into regular brain-flak, we get:

({}{})({}{})

The first one is the standard addition snippet. The second one is effectively a NO-OP.

James

Posted 2016-07-02T00:40:45.547

Reputation: 54 537

1

JavaScript (Node.js), 18 bytes

a=>eval(a.join`+`)

Try it online!

Explanation :

a =>                     // lambda function taking array as input
    eval(               // begin eval
        a.join`+`      // joins all elements in `a` with a `+` sign in between
    )                 // end eval (since this is now a string it gets added up)

Alternate :

JavaScript (Node.js), 9 bytes

x=>y=>x+y

Try it online!

Explanation :

x =>                  // lambda taking x as input 1
    y =>              // which returns lambda with input y
        x + y         // which returns sum of x and y

Muhammad Salman

Posted 2016-07-02T00:40:45.547

Reputation: 2 361

Welcome to PPCG! – Martin Ender – 2018-04-12T08:37:06.480

Thanks. May I ask what you edited ? – Muhammad Salman – 2018-04-12T09:16:53.983

Nvm , found that out. Thanks for the edit. :) – Muhammad Salman – 2018-04-12T09:20:24.293

1

Unnamed, 25 Bytes

Takes 2 numbers from the input area, then adds them together and prints it to the output area.

Try it (paste the code to the leftmost textarea, write the numbers you want to print to the middle textarea in two separate lines, like 5 and 4 in two different lines, and press run)

, # >1 # , # _+.@0.@1 # .

How?

" # " is the command separator. I will explain the others.

,                       /take one input as integer. store it at the current pointer (initially 0)
 >1                     /move the pointer by 1 cell to the right (now is 1)
   ,                    /take one input as integer and store it at the current pointer, now 1
    _                   /assign                                     to cell 1
     +.                 /      the sum of
      @0.@1             /                the numbers at cell 0 and 1
           .            /print the value in the current pointer (which is 1)

Windmill Cookies

Posted 2016-07-02T00:40:45.547

Reputation: 601

is the language complete / Is it a stable version ? – Muhammad Salman – 2018-06-03T08:56:44.693

it is stable except the documentation (I am way too lazy to write the docs) – Windmill Cookies – 2018-06-03T08:58:02.850

Then I highly suggest that you have it added to TIO. You can go here. I suggest that you ping Dennis.

– Muhammad Salman – 2018-06-03T09:16:15.533

no, thanks, I am working on much better languages. I will have them added to tio when I finish them, but not unnamed. unnamed was just like a fun side project of mine, and i was a really bad programmer when I wrote it (I am still very bad, but a little better) – Windmill Cookies – 2018-06-03T09:26:18.050

1

6502 machine code - 8 bytes

A5 08 65 09 85 0A 4C 06

Input stored at 0x08 and 0x09, output storad at 0x0A

Tornado547

Posted 2016-07-02T00:40:45.547

Reputation: 389

1

7, 8 bytes, 22 characters

1717023740344172360303

Try it online!

This program is encoded on disk as (xxd hexdump):

00000000: 3cf0 9f81 c87a 7830                      <....zx0

7 doesn't really support numbers natively, and thus it's hard to define what a number is for the purpose of a function submission. As such, this is a full program, reading from stdin, outputting to stdout (which explains where much of the length comes from).

This program doesn't support negative numbers, because 7 can't input those using numeric I/O (although it can output them). As such, supporting negative numbers would require the use of character input (and a decimal→integer parser), which would make the program much, much more complex.

Explanation

1717023740344172360303
 7 7   7                Stack element separators
1 1 023                 Initial stack
        40344172360303  Initial program (also stored on the stack)
(Implicit: run the initial program, but leave it on the stack)
        4               Swap with blank element between
         0              Escape top stack element, append it to element below

So at this point, we've effectively swapped the program below the 023 element, escaping that element in the process. The 023 is a program in a domain-specific I/O language; and putting the program as the second stack element means that we can discard it (the second stack element is the only one that can be discarded).

          3             Do I/O using top element, discard second element
    0                   Set I/O format: numeric in decimal
     23                 Input via repeating the third stack element

We now have only two stack elements; 1 at the bottom, and the first input in unary just above it (because we repeated the second-last stack element, which was 1, and thus will have a number of 1s).

           4            Swap with blank element between
            4           Swap with blank element between
             172360     Append an escaped representation of "23" to TOS
                   3    Do I/O using top element, discard second element
               23       Input via repeating the third stack element

So now our stack consists of the first input (in unary) directly below the second stack element (in unary).

                    0   Escape top element, appending it to the element below
                     3  Do I/O using top element, and exit

The 3 command exits the program as we're out of stack, but not before it outputs the number we calculated. The number in question will consist of a number of 7s equal to the first number input, followed by a number of 1s equal to the second number input (these are the unescaped and escaped representations of the same command). Numeric I/O treats 1 and 7 as equivalent, and having a value of +1; thus, the unary number gets translated into decimal and output.

ais523

Posted 2016-07-02T00:40:45.547

Reputation: 11

1

Burlesque - 4 bytes

ps++

ps   parse
  ++ sum

Try it online.

mroman

Posted 2016-07-02T00:40:45.547

Reputation: 1 382

How does this work? Can you link to an interactive demo and / or provide instructions on how to execute it? – Οurous – 2018-11-18T21:57:39.420

1ps parses the input into a list and ++ computes the sum of a list. I added a link to the online interpreter. – mroman – 2018-11-18T22:10:31.113

1

Aheui (esotope), 15 bytes(5 characters)

방방다망히

Try it online!


Meet Aheui(아희), A Korean alphabet-based esoteric programming language.

cobaltp

Posted 2016-07-02T00:40:45.547

Reputation: 401

1

Re:direction, 9 characters, 3 bytes

♦►
♦►
◄ ▼

Try it online!

In Re:direction's packed encoding:

F1 F1 B6

(Byte F1 encodes ♦►␤; B6 encodes ◄ ▼).

Explanation

Re:direction is a 2D language that uses a queue of direction commands. At the start of the program, the queue is initialized from user input; an integer n becomes n copies of , then . From that point onwards, whenever we use a direction command, it controls the direction in which the instruction pointer moves but also gets pushed onto the tail of the queue.

The command shifts one direction from that queue, and moves in that direction. So ♦► is effectively a loop that moves any number of from the head of the queue to the tail; as long as the queue starts with , we'll shift it and go right, and hit the in the program, which sends the IP right back where it started (wrapping around the edge of the program) and pushes the to the tail of the queue instead. Once we hit the , it gets deleted from the queue and we move onwards.

We can note that ♦► does not preserve the in the queue. As such, running it twice deletes both from the initial queue, leaving us with a number of equal to the sum of the initial two numbers.

We need to encode the output the same way as the input, meaning that we need to add a and halt the program. A direction command that points to itself will run and then immediately halt the program, so we can use a on a column by itself to do both jobs. We do, however, need to get there; this program uses a to do so (because stray ups and lefts in the queue won't affect the output).

ais523

Posted 2016-07-02T00:40:45.547

Reputation: 11

1

RUST, 29 bytes

Save 5 bytes thank to ASCII-only

Try this on line

fn s(a:i32,b:i32)->i32{a+b}

ASCII-only also beat my solution here

chau giang

Posted 2016-07-02T00:40:45.547

Reputation: 725

18, also you have unneeded spaces anyway – ASCII-only – 2019-01-29T07:48:24.803

@ASCII-only Thank you a lot for your solution. – chau giang – 2019-01-29T08:00:41.780

You forgot to rename the function – ASCII-only – 2019-01-29T08:02:33.580

1lol, now it's 27 bytes not 29 – ASCII-only – 2019-01-29T08:10:50.770

@ASCII-only, thank you, I just updated it, I count all bytes with my eyes so maybe I was wrong – chau giang – 2019-01-29T08:12:06.480

Btw sorry because I can not upvote your comment, I dont know why but it does not show the upvote button in your comment – chau giang – 2019-01-29T08:14:02.273

@ASCII-only, your solution is sweet, I upvoted it! – chau giang – 2019-01-30T03:53:35.653

1

Clam, 4 bytes

p+rr

Try it online!

Explanation

p               print ...
   +               the sum of ...
       r               the first line of STDIN and ...
       r               the second line of STDIN

MilkyWay90

Posted 2016-07-02T00:40:45.547

Reputation: 2 264

1

Re:direction, 9 bytes

▲♦▼
►♦
 ▲

Suprisingly small for a language like this. Re:direction is a language that only uses arrows, a queue, and to go in the direction of the first item on the queue

Explanation

Note: I'll be using .'s to represent instructions I'm not talking about, and I'll split it up into a couple of sections

Input is automatically pushed to the queue as ►'s seperated by ▼'s

▲..
►.      Pushes ▲ into the queue, used as a marker later
 .

...
►♦       Loop that goes through every item of the queue (the input). If its ►, it does nothing to it.
 ▲       If it is ▼, it gets replaced by ▲, which is ignored by the output

.♦▼      If it is an ▲, another ♦ is run, which goes right and removes one item from the queue to make the output correct
.♦       Then, since the ▼ is the only arrow in it's column, it gets pushed to the queue then the program halts
 .

Try it online!

EdgyNerd

Posted 2016-07-02T00:40:45.547

Reputation: 1 106

1

Seed, 11 bytes

4 141745954

Damn, It's quite small

Krzysztof Szewczyk

Posted 2016-07-02T00:40:45.547

Reputation: 3 819

This appears to correspond with the program &&+., which loops infinitely outputting zeroes. You need an @ afterwards – Jo King – 2020-01-07T23:45:16.860

1

Cascade, 4 bytes

#&
+

Pretty self explanatory, uses wrapping so there is only 1 input instruction

Try it online!

EdgyNerd

Posted 2016-07-02T00:40:45.547

Reputation: 1 106

1

Plumber, 244 176 bytes

  []  []      []
      ][=][]
  []=][][=][
[]=]===]]
][]][=[=]]    =]]
[]][   ][===[=[]
 ]][]=][[[=]=]][][
  []]=]=]=]=[]
  ][]=[]][
  []]=][=][]
= =]=]][[=[==
][=]=]=]=]===][=

Old Design (244 bytes)

  []                []
            [][=[]
 [[=[][]  [][]  ][]][=
][[]  ][[=]]]][]=[[]
[]===][]  ][===][]
][][  []    ][  ]     [][]
      [     ][]=][[[===][[
][]]]=][[]=[=]=]=]]==]=]][
  ][=]=]]==]=][]  ][
    [][=][=[[][[=]][
   ==]=]][[=[= =

I thought I had a good solution for a while...except it didn't work with 0 or 1 as the first input. This program consists of three parts: incrementer, decrementer, and outputter.

The decrementer is on the left, and holds the first value. It is incremented, since a 0 would cause an infinite loop (as the program tries to decrement to 0 and gets a negative value). It will decrement the stored value at execution, and send a packet to the incrementer.

The incrementer is on the right, and stores the second input. When the decrementer sends a packet, it increments its stored value, and sends a packet back to the decrementer.

Whenever the decrementer sends the packet to the incrementer, it is checked by the outputter. If the packet is 0, execution stops and the value of the incrementer is read and outputted. It uses a NOT gate, one of the most complicated parts of the program.

Older design (doesn't work with some inputs), 233 bytes

          []          []
          [][]  [][]  =][]
    []=][]=][[=]][
      [][===][  [][===[]
[][]   [        []    ][][
] [===][=]][     ]
][[=[=[=[=[=]=[]][=[[[][
    ][[=[=[=[==[[=[=][
          []]=][=][]
        = =]=]][[=[== 

The new one is flipped to save bytes, and it's really confusing me. This design is the one I worked with for a week or so when designing the interpreter.

Redwolf Programs

Posted 2016-07-02T00:40:45.547

Reputation: 2 561

1

SystemVerilog (HDL) (93 chars)

Here's a pretty simple 8-bit full adder implementation (including input carry for chaining).

module a(input[7:0] a,input[7:0] b,input d,output c,output[8:0] f);
assign f=a+b+d;
endmodule

Inputs: [7:0]a and b, carry bit d.

Outputs: [8:0]f. The top bit can be used as a carry output signal.

Calculuswhiz

Posted 2016-07-02T00:40:45.547

Reputation: 193

1

Bash, 18 bytes

f(){expr $1 + $2;}

dkudriavtsev

Posted 2016-07-02T00:40:45.547

Reputation: 5 781

Wouldn't this be shorter as a program rather than as a function? – Neil – 2016-07-02T18:46:17.660

@Neil Yeah, I'll post that separately. – dkudriavtsev – 2016-07-02T22:02:50.273

1

Bash script, 12 bytes

expr $1 + $2

Save as add.sh, then run bash add.sh [argument] [argument].

dkudriavtsev

Posted 2016-07-02T00:40:45.547

Reputation: 5 781

1I think this should have been posted as an edit to your previous answer. – Dennis – 2016-07-02T22:10:10.813

@Dennis These are somewhat separate: this one has to be run from a file, the other one can be run from the command line. – dkudriavtsev – 2016-07-02T22:12:57.477

2Yes, I'm aware. I don't think they're different enough to warrant separate answers though. The other does exactly the same; it just wraps the program in a function declaration. – Dennis – 2016-07-02T22:18:09.343

@Dennis Okay... – dkudriavtsev – 2016-07-02T22:18:57.473

1

Prelude, 4 bytes

??+!

Requires my modified Prelude interpreter which uses decimal I/O.

Like several other answers, this is just read, read, add, write.

Martin Ender

Posted 2016-07-02T00:40:45.547

Reputation: 184 808

1

Befunge - 5 Bytes

&&+.@

& - Request int from user and push to stack

+ - Pop top two elements from stack and add and push result

. - Pop value and output as int

@ - End program

Try it here (Although you will have to copy/paste into the text area)

Edit: oops, didn't notice the earlier (identical) befunge answer, I'll leave this here unless I'm told to delete it, not sure of the opinion on that.

Yann

Posted 2016-07-02T00:40:45.547

Reputation: 151

1

GO, 29 bytes

func (a,b int)int{return a+b}

Not that much to say

Sefa

Posted 2016-07-02T00:40:45.547

Reputation: 582

1

Yup, 6 bytes

0*-*-#

Try it online!

Explanation

0*-*-#
0        push 0 to the stack   [0]
 *       place input           [0 a]
  -      subtract              [-a]
   *     place input           [-a b]
    -    subtract              [-a-b]
                             = [b+a]
     #   output

As a function on -cheat mode, 9 bytes:

0~--0~-=+

Try it online!

Conor O'Brien

Posted 2016-07-02T00:40:45.547

Reputation: 36 228

1

SML, 3 bytes

op+

This is the prefix version of the infix +. If we input it like this in an interpreter (for example Moscow ML), it's type is displayed

- op+;
> val it = fn : int * int -> int

which tells us how to use it: Given a tuple of integers, an integer will be returned.

- op+(17,25);
> val it = 42 : int 

Laikoni

Posted 2016-07-02T00:40:45.547

Reputation: 23 676

1

GAP, 2 Bytes

\+

The backslash is GAP's way to turn an infix operator (and some more, there is also \[\] for indexing) to a function.

Here is an example use:

gap> \+(4,3);
7

Christian Sievers

Posted 2016-07-02T00:40:45.547

Reputation: 6 366

1

jq, 3 characters

add

Sample run:

bash-4.3$ jq 'add' <<< '[5,16]'
21

On-line test

manatwork

Posted 2016-07-02T00:40:45.547

Reputation: 17 865

1

Elixir, 7 bytes

& &1+&2

Anonymous function defined using the capture operator. Another version is &(&1+&2), however this approach saves 1 byte. The verbose version is fn a,b->a+b end - 15 bytes.

Full program with test case (yes, the . in the function call is mandatory!):

s=& &1+&2
IO.puts s.(1,6) #7

Try it online on ElixirPlayground !

adrianmp

Posted 2016-07-02T00:40:45.547

Reputation: 1 592

1

QBIC, 6 bytes

::?a+b

It takes two cmd line params as numbers (with two :'s), names them a and b, and adds them while printing (?).

steenbergh

Posted 2016-07-02T00:40:45.547

Reputation: 7 772

1

Ruby, 17 bytes

** Edit: Big thank you to @steenbergh and @TùxCräftîñg for their help **

def c(a,b)a+b end

BoeNoe

Posted 2016-07-02T00:40:45.547

Reputation: 121

Edited the answer. – BoeNoe – 2016-10-20T17:37:24.233

@manatwork Edited. – BoeNoe – 2016-10-21T11:21:31.703

@manatwork What do you mean? – BoeNoe – 2016-10-21T11:24:20.923

@manatwork Oh, ok. – BoeNoe – 2016-10-21T11:27:01.633

@manatwork Edited. – BoeNoe – 2016-10-21T11:27:59.607

Excess space between function arguments? – steenbergh – 2016-10-21T12:04:23.013

@steenbergh Spaces counts too? – BoeNoe – 2016-10-21T12:05:04.797

@steenbergh And can I use echo instead of return? – BoeNoe – 2016-10-21T12:08:31.013

Yes, I believe you can use ECHO instead of Return. Also, whitespace counts in the bytecount, so remove any unnecessary spaces.

– steenbergh – 2016-10-21T12:14:16.890

@steenbergh Thanks for you help! – BoeNoe – 2016-10-21T12:17:01.220

The return is unnecessary: def c(a,b)a+b end, and BTW making it a lambda is shorter (->a,b{a+b}) – TuxCrafting – 2016-10-28T15:09:31.760

1

C, 49 bytes

main(a,b){scanf("%d %d",&a,&b);printf("%d",a+b);}

Can't really do much to golf it down.

For fun:

The following works only if 0 <= sum < 256 (it's 59 bytes long):

a;main(c,v)char**v;{return a++&2?c-3:main(c+atoi(*++v),v);}

Use gcc to compile, and ./a.out [your 2 nums]; echo $? to run it.

Here's the ungolfed version of that program:

/* Global int auto-initialized to 0 */
a;

/* The main method with two int params */
/* 'c' is argc, and 'v' is argv */
main(c, v)

/* Yes, this is valid. It defines 'v' as a char** */
char** v;

{
    /* Checks to see if a == 2, and increments a.
     * I only want recursion to happen twice. */
    if (a++ & 2)
    {
        /* Since "argc" is 3, we need to subtract it from the final answer */
        return c - 3;
    }
    else
    {
        /* Get the next int value of "argv" and add it to 'c'.
         * Then call main() again with the updated value */
        return main(c + atoi(*++v), v);
    }
}

So, main() returns the value of the sum of the two numbers (essentially, I'm forcing it to return a custom exit code). The program won't output the exit code, so calling echo $?, in the same command as running the program, outputs the return value of that program.

The range of exit codes only exist between 0 and 255, so if you run the program trying to sum 255 and 1, it will wrap around and output 0.

homersimpson

Posted 2016-07-02T00:40:45.547

Reputation: 281

The format string doesn't need a space. "%d" (like most conversions other than %c and %[) skips leading white-space on its own.

– Peter Cordes – 2017-12-17T19:49:22.103

1

Befunge, 7 bytes

#v&<
 +
 .
 @

Befunge is an esoteric language that can execute in any cardinal direction on a 2 dimensional plane. Executing left to right from the top left (default) we get the following set of operations ((x,y) = coordinates of operation with (0,0) in the top left)

(0,0): skip next cell in execution path (1,0)
(2,0): ask for user input and push it to the stack
(3,0): reverse direction of execution
(2,0): ask for user input and push it to the stack
(1,0): begin executing downward
(1,1): pop first two values on stack, add them and push result
(1,2): pop stack and output value
(1,3): end

&&+.@ would also work, and in only 5 bytes, but is not nearly as cool

Will Ross

Posted 2016-07-02T00:40:45.547

Reputation: 11

Invalid, you did not count the newline nor the spacing. Also, this is code golf, the aim is conciesness, not coolness – ASCII-only – 2019-01-29T07:53:24.713

1

Swift, 1 byte

+

since operator + is defined as function(public func +(lhs: Int, rhs: Int) -> Int)

Apollonian

Posted 2016-07-02T00:40:45.547

Reputation: 61

1

C, 66 bytes

Typical C omissions with regard to declarations, header files, and return statements. This actually works for any number of decimal integers (up to the limitations of one's shell), including none. The program can be invoked with ./a.out 1 2 [...], as an example.

main(c,v,x)char**v;{x=0;while(c-1)x+=atoi(v[--c]);printf("%d",x);}

Or, more legibly:

main(c,v,x) char**v; {
    x=0;
    while(c-1) x+=atoi(v[--c]);
    printf("%d",x);
}

James Murphy

Posted 2016-07-02T00:40:45.547

Reputation: 267

You don't need to have a full program. Just int f(int a,int b){return a+b;} would probably suffice. – dkudriavtsev – 2016-11-01T02:11:06.327

The challenge stated program or function. I make no claims to have the best solution. Additionally, another user has already provided a standalone function, and to produce an identical one would not contribute much. – James Murphy – 2016-11-01T02:27:26.427

0

PHP, 5 bytes

bcadd

PHP has the BC-Math library for arbitrary length integers.
bcadd adds the numbers represented by the two string operands.

A full program would need 21 bytes:

<?=$argv[1]+$argv[2];

alright 20 bytes with array_sum (assuming that the file name does not start with a digit).

Titus

Posted 2016-07-02T00:40:45.547

Reputation: 13 814

0

Carrot, 5 bytes, non-competing

$^F+$

Try it online! (no permalink)

Input numbers are separated by a newline like so:

x
y

$ in c^rrot mode (the code before the first ^) pops the first value from the input array. So now the stack contains x. After that, this value is converted to a number using F. Then we add it with $, the next value in the input array, ie y. Output is implicit, so this outputs x+y.

An alternative at the cost of 1 byte would be:

#^A + 

note the trailing space

# takes all of the input (separated by a space), and converts it to an Array by splitting on s. Then encounter a +, which is given a as its argument, meaning that all the elements of the array will be summed up.

user41805

Posted 2016-07-02T00:40:45.547

Reputation: 16 320

0

Billiards, 7 characters = 11 bytes, non-competing

Language made after the challenge.

↧ # Takes an input
↧ # Takes another input
+ # Adds them together
P # Outputs as an integer

Alternatively, for the same number of bytes:

↧↧ # Takes two inputs
+/ # Adds them together; the '/' deflects the second input into the '+'
P  # Output as an integer

HyperNeutrino

Posted 2016-07-02T00:40:45.547

Reputation: 26 575

0

Scala, 17 Bytes

x:Int=>y:Int=>x+y

Stefan Aleksić

Posted 2016-07-02T00:40:45.547

Reputation: 119

0

REXX, 15 bytes

arg a b
say a+b

idrougge

Posted 2016-07-02T00:40:45.547

Reputation: 641

0

J, 4 bytes

I've defined a function f and set it to the built-in addition operator.

f=:+

Bijan

Posted 2016-07-02T00:40:45.547

Reputation: 781

0

AHK, 15 bytes

1+=%2%
Send,%1%

1 and 2 are, by default, the first two arguments passed in to a program. Sometimes you have to escape them with percent signs so it doesn't confuse the variable 1 with the number one.

Engineer Toast

Posted 2016-07-02T00:40:45.547

Reputation: 5 769

0

Visual Basic.NET, 39 bytes

Function F(x,y)
Return x+y
End Function

Without Option Strict On (which you definitely want for any real coding), no data types are required (As type).

With Option Strict On:

Function F(x As Integer,y As Integer) As Integer
Return x+y
End Function

Stephen

Posted 2016-07-02T00:40:45.547

Reputation: 12 293

0

Decimal, 12 bytes

81D81D41D301

Explanation:

81D   ; builtin - read INT from STDIN, push to stack
81D   ; builtin - read INT from STDIN, push to stack
41D   ; math +, pop values used, push result
301   ; print from stack to STDOUT

MD XF

Posted 2016-07-02T00:40:45.547

Reputation: 11 605

TIO link coming as soon as the latest Decimal version is pulled to TIO. – MD XF – 2017-06-04T21:33:11.873

0

Standard ML (MLton), 3 bytes

op+

Try it online!

An anonymous function that behaves as the + operator, on a tuple of two integers.

musicman523

Posted 2016-07-02T00:40:45.547

Reputation: 4 472

0

Check, 2 bytes

+p

Input is from command-line args.

+ adds the two numbers, and p prints it.

Esolanging Fruit

Posted 2016-07-02T00:40:45.547

Reputation: 13 542

0

SQL, 19 bytes

SELECT SUM(a)FROM t

Our rules allow SQL to input via a pre-existing named table (in this case table t with INT field a), so just SUM it up and output the results.

Works for however many rows are in the input table.

BradC

Posted 2016-07-02T00:40:45.547

Reputation: 6 099

0

Element, 4 bytes

__+`

Explanation:

_  input to stack
_  input to stack
+ add top two stack elements
`  pop to output

https://tio.run/##S81JzU3NK/n/Pz5eO@H/fyMFLmMA

aAaa aAaa

Posted 2016-07-02T00:40:45.547

Reputation: 141

0

Excel VBA, 8 Bytes

Anonymous VBE immediate window function that takes arguments from the range [A1:B1] and outputs their sum to the VBE immediate window

?[A1+B1]

Taylor Scott

Posted 2016-07-02T00:40:45.547

Reputation: 6 709

0

MS Excel / Google Sheets, 6 Bytes

Anonymous Worksheet function that takes input from the range A1:B1 and outputs their sum to the worksheet cell that holds this formula.

=A1+B1

Taylor Scott

Posted 2016-07-02T00:40:45.547

Reputation: 6 709

0

LOLCODE, 75 bytes

HAI 1.3
I HAS A J
GIMMEH J
I HAS A Q
GIMMEH Q
VISIBLE SUM OF J AN Q
KTHXBYE

Try it online!

FantaC

Posted 2016-07-02T00:40:45.547

Reputation: 1 425

0

DUP, 37 bytes

[0[`$32-][\10*($48-)+\%]#%]⇒II(I)+.

Both integers have to be space terminated (ASCII 32)

Explanation, taking example 11+3:

[0[`$32-][\10*($48-)+\%]#%]⇒I                   {I defines an operator that converts space-terminated character strings to integer numbers}
[                         ]⇒I                   {Definition of operator I}
 0                                              {push 0 on ds (data stack)}
  [cond.][    block    ]#                       {while condition nonzero do block}
   `                                            {read character from STDIN to ds}
    $                                           {DUP ds top value}
     32-                                        {push 32 on ds, SUB}
          \                                     {SWAP topmost ds values}
           10*                                  {push 10 on ds, MUL}
              (                                 {move ds top value to rs (return stack)}
               $                                {DUP}
                48-                             {push 48, SUB}
                   )                            {move rs top back to ds}
                    +                           {ADD}
                     \%                         {SWAP, POP}
                         %                      {POP}

I reads in numbers as single characters and converts them to decimal numbers (basically by a base 10 shift left, add loop). I also checks if a terminating space is found, and if that’s the case, exits the read in loop and removes junk from the stack.

Actual program:

I                                               {Read in first integer character by character}
 (                                              {move ds top to rs}
  I                                             {read in second integer}
   )                                            {move first integer back from rs to ds}
    +                                           {ADD}
     .                                          {output sum to STDOUT}

Try it out in this online DUP interpreter.

M L

Posted 2016-07-02T00:40:45.547

Reputation: 2 865

0

ARBLE, 3 bytes

a+b

Try it online!

ATaco

Posted 2016-07-02T00:40:45.547

Reputation: 7 898

0

Spiral, 6 bytes

0;;+,!

Interpreter

Steadybox

Posted 2016-07-02T00:40:45.547

Reputation: 15 798

0

Whispers, 34 bytes

> Input
> Input
>> 1+2
>> Output 3

Try it online!

Don't worry, this doesn't just Output 3, or perform 1+2

caird coinheringaahing

Posted 2016-07-02T00:40:45.547

Reputation: 13 702

0

C++, 30 bytes

[](auto a,auto b){return a+b;}

Try it online

Johan du Toit

Posted 2016-07-02T00:40:45.547

Reputation: 1 524

1(int a,int b) is shorter, and within the rules. – Toby Speight – 2018-06-04T16:25:08.323

0

Pyth - 5 Bytes

AQ+GH

A      Set variables G and H to the first two elements of
 Q     Input;
       Implicitly Print
   G   G
  +    plus
    H  H

Tornado547

Posted 2016-07-02T00:40:45.547

Reputation: 389

1s? – hakr14 – 2018-04-15T00:56:33.863

0

SNOBOL4 (CSNOBOL4), 26 bytes

 OUTPUT =INPUT + INPUT
END

Try it online!

Giuseppe

Posted 2016-07-02T00:40:45.547

Reputation: 21 077

0

Beatnik, 9 bytes

x x kg ja

Try it online!

I/O in codepoint values, so !! -> B, B! -> c. Works with larger numbers on Unicode interpreters.

NieDzejkob

Posted 2016-07-02T00:40:45.547

Reputation: 4 630

0

√ å ı ¥ ® Ï Ø ¿, 3 bytes

i+o

Try it online!

i+o
i    takes input as a flattened list
 +   adds
  o  outputs

FantaC

Posted 2016-07-02T00:40:45.547

Reputation: 1 425

0

jamal, 22 characters

(12 characters code + 10 characters command line options)

{#+ {a} {b}}

Strictly because the question owner wrote “I'm interested to see how it can be implemented”.

Sample run:

bash-4.4$ perl jamal.pl -Da=5 -Db=16 add.jam
21

manatwork

Posted 2016-07-02T00:40:45.547

Reputation: 17 865

0

m4, 19 characters

(9 characters code + 10 characters command line options)

eval(a+b)

Strictly because the question owner wrote “I'm interested to see how it can be implemented”.

Sample run:

bash-4.4$ m4 -Da=5 -Db=16 <<< 'eval(a+b)'
21

Try it online!

manatwork

Posted 2016-07-02T00:40:45.547

Reputation: 17 865

0

FRACTRAN, 3 bytes

2/3

Take 2^a*3^b as input, return 2^(a+b).

Try it online!

I'm not sure whether or not extra bytes should be added for input encoding and output decoding.

Vincent

Posted 2016-07-02T00:40:45.547

Reputation: 601

0

Flobnar, 4 bytes

&
+@

Try it online!

Esolanging Fruit

Posted 2016-07-02T00:40:45.547

Reputation: 13 542

0

F# (Mono), 3 bytes

(+)

In F#, the + operator is defined as a function named (+).

The following prints 3 and shows how to pass parameters to this function. To me, this is the clearest way to see that (+) is actually a function.

printf "%d" ((+) 1 2)

Try it online!

dana

Posted 2016-07-02T00:40:45.547

Reputation: 2 541

0

PHP, 20 bytes

Assuming the script will always have 2 arguments

<?php
$argv[0] = 10;
$argv[1] = 23;
?>
<?=array_sum($argv); // Well, all the arguments are stored on the $argv array
                     // the array can just be added

Try it online!

Francisco Hahn

Posted 2016-07-02T00:40:45.547

Reputation: 591

0

RTFM, 24 bytes

Btw, it's my first answer on PPCG.

041 x 041 y 070 010[x,y]

TeslaX93

Posted 2016-07-02T00:40:45.547

Reputation: 179

1Welcome to the site! – Post Rock Garf Hunter – 2018-12-27T15:13:03.383

0

Obx, 3 bytes

Obx is an abandoned language created by Phase in 2016.

+xy

With an input of 1 and 2, this program would output 3. Let's learn why.

+xy creates a function that adds x (the first argument) and y (the second argument). The last function created is called with whatever the input is.

user85052

Posted 2016-07-02T00:40:45.547

Reputation:

0

Owk, 13 bytes

Owk is an abandoned language created by Phase.

a:λx.λy.x+y

This is written in an unofficial fork(but it's shorter):

a:x+y

user85052

Posted 2016-07-02T00:40:45.547

Reputation:

2What do you mean Owk doesn't support input? Don't you have lambdas? A lambda that takes variables as arguments and returns a value counts as valid input/output. Hardcoding two characters into your program is not. – Value Ink – 2019-09-21T03:03:15.637

0

Pepe 19 bytes

REeerEeeREEEEEEReEE

Try it not online but at the online interpreter

My first Pepe answer... made me want to reeeeeee (not reeally)

REee #Input first integer
rEee #Input second integer
REEEEEE #Add two integers
ReEE #Print result as integer

Lyxal

Posted 2016-07-02T00:40:45.547

Reputation: 5 253

0

1+, 4 bytes

..+:

Pretty much trivial. I just want to get 1+ into those catalogue.

HighlyRadioactive

Posted 2016-07-02T00:40:45.547

Reputation: 1 585

0

Python 3, 14 bytes

lambda x,y:x+y

Pretty self-explanatory lol

Sagittarius

Posted 2016-07-02T00:40:45.547

Reputation: 169

0

Quantum Circuit 6*Nbits+1 Gates (25 for two 4-bit numbers)

Circuit Diagram

Based on the ripple adder of Cuccaro et al

  • Qubits 0/9 should be left as 0
  • 1:3 represent A in binary
  • 5:8 represent B in binary
  • Answer appears in qubits 5:9

Try it online!

DeathIncarnate

Posted 2016-07-02T00:40:45.547

Reputation: 916

0

hashmap (Yes, the name starts with a lowercase letter.), 3 bytes

hh+
h   Take input
 h  Take input
  + Get the sum

user47018

Posted 2016-07-02T00:40:45.547

Reputation:

0

C, 25 Bytes

p(a,b){printf("%d",a+b);}

Usage

p(a,b){printf("%d",a+b);}
main(c,v)char**v;{p(atoi(*++v),atoi(*++v));}

Or, if you want a full program: (+29 chars)

main(c,v)char**v;{printf("%d",atoi(*++v)+atoi(*++v));}

Take 2 arguments and outputs the results in STDOUT

Giacomo Garabello

Posted 2016-07-02T00:40:45.547

Reputation: 1 419

You dont need to print it, a simple return will suffice. – Karl Napf – 2016-10-27T15:22:46.797

0

hashmap, 10 bytes

i" "ĥdĐ+

Explanation:

i" "ĥdĐ+
i        Take input
 " "     Push space
    ĥ    Split the input by space
     dĐ  Convert the list to a double then flatten the list
       + Add them together

user47018

Posted 2016-07-02T00:40:45.547

Reputation:

0

Batch, 52 Bytes

set/p x=
set/p y=
set/a z=%x%+%y%
echo %z%
pause>nul

This is the lowest byte number you will have while still making the program work. I did the challenge by making a program, not just what the operation was. This method will allow you to input any number and then any other number, including negatives, and the program will output a number.

Nitrate

Posted 2016-07-02T00:40:45.547

Reputation: 11

Is this a full program? I don't know batch but it looks like the numbers get inputted by editing the program rather than a prompt of some kind – Blue – 2016-07-06T16:32:28.310

Hey Nitrate. Welcome to PPCG. A few problems with this post: this is [tag:code-golf], which means you need to shorten your code to as short as possible. You don't have to take input like this - you could possibly take it as command line arguments to shorten it. Nice to see you here, m9. – Addison Crump – 2016-07-06T22:44:58.793

@muddyfish The /p switch allows you to set a variable equal to a line of input entered by the user. – Dennis – 2016-10-18T15:36:02.377

0

S.I.L.O.S 38

readIO 
a = i
readIO 
a + i
printInt a


For documentation see the repo https://github.com/rjhunjhunwala/S.I.L.O.S Fee free to try this code online!

Rohan Jhunjhunwala

Posted 2016-07-02T00:40:45.547

Reputation: 2 569

Perhaps you meant printInt instead of prinInt – Leaky Nun – 2016-08-26T15:29:08.657

How does it work? – Leaky Nun – 2016-08-26T15:39:05.170

@LeakyNun whoopsmy bad, fixing now – Rohan Jhunjhunwala – 2016-08-26T16:16:18.607

2 bytes off – Leaky Nun – 2016-08-26T16:20:21.130

@LeakyNun thanks, you showed me a feature I didn't even know my language had! I though readIO must have a prompt after it! – Rohan Jhunjhunwala – 2016-08-26T16:21:05.200

It doesn't have to have a prompt after it, but it must have a whitespace after it (you deleted it!) – Leaky Nun – 2016-08-26T16:24:27.917

@LeakyNun whoops – Rohan Jhunjhunwala – 2016-08-26T16:29:35.900

0

Maple, 3 bytes

`+`

Usage:

> `+`(1,2)
  3

DSkoog

Posted 2016-07-02T00:40:45.547

Reputation: 560

0

Ruby, 17 bytes

def f(i,j)i+j;end

Functions in Ruby return the last evaluated expression.

dkudriavtsev

Posted 2016-07-02T00:40:45.547

Reputation: 5 781

3Anonymous Proc is also acceptable: ->i,j{i+j}. (You call it like ->i,j{i+j}[3,4].) – manatwork – 2016-07-27T11:48:58.960

0

Gema, 13 characters

* *=@add{*;*}

Sample run:

bash-4.3$ gema '* *=@add{*;*}' <<< '5 16'
21

manatwork

Posted 2016-07-02T00:40:45.547

Reputation: 17 865

0

golflua, 12 characters

\f(a,b)~a+b$

Sample run:

> \f(a,b)~a+b$ 
> w(f(5,16))
21

manatwork

Posted 2016-07-02T00:40:45.547

Reputation: 17 865

0

MoonScript, 10 characters

(a,b)->a+b

Sample run:

bash-4.3$ .luarocks/moon <(echo 'print ((a,b)->a+b)(5,16)')
21

manatwork

Posted 2016-07-02T00:40:45.547

Reputation: 17 865

0

SQF, 19

Using the function-as-a-file format:

params["x","y"];x+y

Call as: [X, Y] call NAME_OF_COMPILED_FUNCTION

Οurous

Posted 2016-07-02T00:40:45.547

Reputation: 7 916

0

RubyGolf, 15 bytes

p gets.i+gets.i

code is so short it hit the character limit. ugh.

New language created by me, interpreter going up soon. non competing.

dkudriavtsev

Posted 2016-07-02T00:40:45.547

Reputation: 5 781

0

Y, 5 bytes

{α+β}

Anonymous function returning the sum of it first and second argument.

TuxCrafting

Posted 2016-07-02T00:40:45.547

Reputation: 4 547

0

JavaScript, 27 bytes

function s(a,b){return a+b}

I thought this needed a semi-colon after the return statement, but when typing it into the Chrome Console, it works fine without.

Pete Arden

Posted 2016-07-02T00:40:45.547

Reputation: 1 151

a=>b=>a+b, but then it will be a duplicate – TuxCrafting – 2016-10-27T18:27:27.483

Also (a,b)=>a+b is better, but still, duplicate – Yotam Salmon – 2016-10-30T21:27:58.743

0

2 cases:

Pyth, 5 bytes

Input format: n1, n2

code: +hQeQ

Pyth, 1 byte

Input format: n1+n2

code: Q

(But I'm not sure if the second is called "cheating" :-P)

Yotam Salmon

Posted 2016-07-02T00:40:45.547

Reputation: 201

0

Java, 91 bytes

interface M{static void main(String[]a){System.out.print(new Long(a[0])+new Long(a[1]));}}

Usage: java M <num1> <num2>

Tips appreciated.

Niclas M

Posted 2016-07-02T00:40:45.547

Reputation: 61

1(a,b)->a+b as a lambda expression – Pavel – 2017-01-09T09:23:41.903

1@Pavel Or a->b->a+b to save 1 more byte. – Kevin Cruijssen – 2017-09-26T15:07:01.833

-1

Wireworld (Non-Competing)

This much answers, no wireworld? Man, Wireworld had these binary adders laying around from ages ago!

Where I got the binary adder

Matthew Roh

Posted 2016-07-02T00:40:45.547

Reputation: 5 043

8This could be improved if it was a full adder and if you included the cell count. – NonlinearFruit – 2017-03-03T22:50:57.120

1Did you get around to implementing the top comment? – MilkyWay90 – 2019-07-26T03:56:39.823

-1

Racket 7 bytes

(+ a b)

Usage:

(define (f a b)
  (+ a b)
)

Testing:

(f 5 6)

Output:

11

rnso

Posted 2016-07-02T00:40:45.547

Reputation: 1 635