# Goal:

Given two natural numbers (integers from 0 to infinity), output a number that is not the sum of those numbers, but is a natural number.

# Example solutions (TI-Basic):

• A+B+1

• not(A+B)

# Invalid solutions:

• A+B-1 (for inputs 0,0, it returns -1, which is not natural)

• "ABC" (ABC is not a number)

# Notes:

• The output must always be a sum of two natural numbers (which is actually just a natural number)

• -1, undefined, infinity, NaN and Error messages are not natural numbers. For our purposes, 0 is natural (although not all mathematicians agree).

• Maybe we take the numbers as strings and output as a string? – xnor Feb 13 '17 at 3:01
• Can the output have leading zeroes? – Kritixi Lithos Feb 13 '17 at 8:27
• I presume overflows need to be taken into account, so the result of 2^32 -1 and 2 should not be negative, right? – adrianmp Feb 13 '17 at 12:28
• Just a small remark because I like to pay attention to useless details: 0 is not a natural number. If you change the first sentence to "Given two non-negative integers ...", there won't be any useless detail left for me to comment on. :) – peech Feb 13 '17 at 17:11
• @peech This is not true. 0 is considered a natural number under some definitions. You cannot see it because it has been deleted but there has been an extensive conversation on this matter. – Post Rock Garf Hunter Feb 13 '17 at 17:16

# Carrot, 3 bytes

1$$ Try it online! (input is newline separated) Similar to ais529's answer, except this takes care of leading zeroes. This outputs 1 concatenated with both the input numbers. So 5\n6 outputs 156. Alternate solutions: ### 6 bytes 1$$^*1


Same thing as the above solution, but concatenates it with a copy of itself. So 5\n6 becomes 156 which then becomes 156156.

### 8 bytes

#^A +1+


(note the trailing space, the input is space separated this time)

#^A +1+
#^                        //gets all of the input
A                       //convert it an array splitting on spaces
+1                     //add 1 to each of the array's elements
+                    //sums up all the elements in the array


# C#, 32 bytes

## Golfed

int i(int x,int y){return++x+y;}


## Ungolfed

int i (int x, int y)
{
return ++x+y; //Returns X+Y+1
}


## Ruby, 9 bytes (8 + -n flag)

p~/1/||1


Input 2 integers separated by comma or space or semicolon or just whatever.

### Explanation:

If the input string does not contain any '1', output '1' (since the sum can't be one).

If the input string is 3 characters long, the position of the first one can be 0 or 2, the sum can't be zero, and only '1 1' has sum two (but the first '1' is at position zero).

If the input string is longer, we don't care, the sum will be bigger than one and bigger than the position of the first '1'.

## Pyke, 1 byte

q


Try it here!

This is the only 1 byte solution that works in Pyke, all the others have collisions.

## Javascript (ES6), 10 Bytes

x=>y=>!x+y


Put f= before the code and run like f(x)(y).

This will output y plus either 0 or 1 depending on whether x is truthy or falsy, respectively.

Thanks to TomDevs for the bytes saved

• You can save 1 byte by currying and the output doesn't have to be 0 or 1, so you can save a further 4 bytes: x=>y=>!x+y, at is ran by (x=>y=>!x+y)(1)(2) – Tom Feb 13 '17 at 11:28
• @TomDevs Oh yea I totally forgot about currying and thanks for the output tip as well. – user64039 Feb 13 '17 at 11:42

## QBIC, 8 bytes

a bit uninteresting:

::?a+b+1


This just takes A and B from the cmd-line, adds them plus 1.

# CJam, four 3 bytes

q~=


Try it online!

Explanation

q~   e# Read the input and eval it (pushes the numbers on the stack).
=  e# Check equality.


# Javascript, 12 bytes

(a,b)=>a+b+1


Accepts 2 numbers inside a closed lambda and return their sum plus 1

Example:

((a,b)=>a+b+1)(1, 2)
// 4

• You can save two bytes by removing the outer pair of parentheses :-) – ETHproductions Feb 13 '17 at 15:01
• I think that will break the IIFE – svarog Feb 13 '17 at 15:03
• We allow any expression that returns a reusable function as a valid entry. Here, (a,b)=>a+b+1 is a perfectly valid function expression; you can assign it to a function with f= and then call it like f(1, 2) as many times as you want. – ETHproductions Feb 13 '17 at 16:21
• currying, i.e. a=>b=>a+b+1 is shorter. you then call it with f(1)(2) – FlipTack Feb 13 '17 at 19:55

# O, 4 bytes

jj=o


The same as other implementations. Get the numbers, test the equality and output. Try it here

j    Number input
j   Number input
=  Equal to
o Print object


# Forth, 5 bytes

I didn't see Forth on the list, this is the A+B+1 solution.

+ 1 +


It adds the top 2 numbers on the stack, then adds one to it.

The answer will be the top value on the stack.

Example:

=> 4, 5
+ 1 +
=> 10

• This can be + 1+, since there is a separate word for 1+. But according to other answers, you could just use =. Also, I'm pretty sure Forth needs to use . for output unless you define a new word. This is as close to a snippet as you can get. – mbomb007 Mar 8 '17 at 14:38

# Clojure, 11 bytes

#(+ % %2 1)


Unoriginal. Just adds 1 to the sum of % and %2 (the arguments to the function).

# Beam, 4 bytes

This seems a bit cheaty, but it reads from the input (characters only) and outputs the ASCII values for each.

>r:!


Try it online!

>     # redirect right
:   # output numeric value of beam
!  # if beam <> 0 reflect back


The Halt command is required on here as the beam just disappears into the aether.

# Cheddar, 11 bytes

(a,b)->a-~b


Try it online!

# Hexagony, 11 bytes

?}?@!<."+)/


Prints X + Y + 1

Try it online!

The expanded Hex:

  ? } ?
@ ! < .
" + ) / .
. . . .
. . .

1. read into the initial memory edge.
2. go forward to the right and read into that one.
3. wrap around to the middle row.
4. go backward to the left and sum the other edges into this one.
5. increment.
6. redirect NW then W to save a byte.
7. print and exit.

# SQLite, 23 22 bytes

Saved 1 byte thanks to MickyT

select 1+sum(v)from i;


By default, SQL variants can take input from a named table. In this case it takes two numbers from the column v in the table i, sums them, and adds 1.

Try it online!

• You can save a byte switching the order of the addition and removing the space before the from. select 1+sum(v)from i; – MickyT Feb 14 '17 at 20:55

# C (gcc), 13 bytes

n(a,b){a=&b;}


returns b's address in memory, though it's slighty cheaty since the user is able to predict the address of b.

Try it online!

• Very nice! I was trying to get less than 14 and couldn't! – Albert Renshaw Feb 26 '17 at 18:57
• why not n(a){a=&a;} – l4m2 Dec 15 '17 at 18:50
• @l4m2 The question requires 2 inputs – Ahemone Dec 17 '17 at 9:37
• n(a){a=&a;} main(a,b){return n(1,2);} works fine – l4m2 Dec 17 '17 at 10:05
• Do you know why that works? – Ahemone Dec 17 '17 at 10:25

# PHP, 22 bytes

eval("echo $argn+1;");  A port of ConnorLSW´s answer. Run with echo "<a>+<b>" | php -R '<code>'. # Milky Way 2 bytes b!  Checks equality. http://meta.codegolf.stackexchange.com/a/8493/63187 allows me to assume the inputs are pushed to stack. Thank you Zach Gates! I out golfed him in his own language :P • You still need to output your result (use ! or ¡). Best alternative I've come up with so far is l+¡. – Zach Gates Mar 2 '17 at 15:04 • @ZachGates OK thanks! Good luck – Christopher Mar 2 '17 at 15:13 • @ZachGates one I had was +R+! Then found the other way – Christopher Mar 2 '17 at 16:13 # ///, 10 bytes + input /0/1//+//[input A]+[input B]  Obviously [input A] and [input B] are supposed to be replaced with the appropriate inputs Try it online! Changes 0's to 1's, then concatenates the strings. This works because: • For A,B>0, join(A,B)>A+B • join(A,B)>join(C,D) if A>C or B>D • The function f(x)='change 0's to 1's in the digits of x' is always at least x So we have join(f(A),f(B))>f(A)+f(B)>=A+B. And if one or both of the inputs are 0, we have join(1,B)>1+B>0+B, join(A,1)>A+1>A+0 and join(1,1)=11>0+0. Note 1: This type of input has been approved by the community Note 2: This output doesn't give leading 0's either Note 3: Less bytes than Python, PHP, C#, C, Powershell and more! # Python, 25 17 bytes Takes an array of numbers n, and returns their sum + 1: lambda n:sum(n,1)  I just translated https://codegolf.stackexchange.com/a/111845/66068 into python. • Anonymous functions are allowed here so you can remove the f= to save 2 bytes. Also replace nums with n to save 6 bytes. lambda n:sum(n,1) for 17 bytes. Also your original is 25 bytes. – caird coinheringaahing Apr 1 '17 at 11:59 ## Keg, 5 bytes Input two natural numbers separated with spaces. ?(+).  Sums the whole stack. The answer is guaranteed to be invalid, since what it sums is the charcodes of the numbers. TIO # Lua, 25 bytes x={...}print(x[1]+x[2]+1)  Try it online! Just a trivial A+B+1 solution. ## Chaincode, 2 bytes a+  Explanation: a #Adds two input values + #Increment  # Labyrinth, 6 bytes ??+)!@  Takes two number inputs, prints their sum + 1. # Scala, 26 Bytes var n=(a:Int,b:Int)=>a+b+1  # Clack, 3 bytes 1++  Since clack has very few instructions at the moment, the shortest method is to just push 1, the two numbers, and add them. # Powershell, 15 Bytes ("$args"|iex)+1


input is in any standard mathematical format, 1+1,2+2,5123-123213,200*99,1234/555 etc.

Just takes input, invokes (calculates) it, then adds one at the end.

# C, 18 bytes

#define f(a,b)a==b


try it online

• #define f(a)a== calling currying lol – l4m2 Dec 17 '17 at 10:09

# <><, 3 bytes

Also see this post, but <>< needs the explicit print and termination so we can't go under 3 bytes.

=n;


But this is a pretty boring solution. There are two 5 byte solutions

1nnn;


and

1++n;


that are only slightly more interesting. For input a and b, the first one works by printing 1ba and the second by printing a+b+1.

Here is a TIO test bench where bytes 2-5 should be replaced by the first 4 bytes of a solution.

# Java - 44 bytes

int n(int a,int b){return Math.abs(a+(-b));}


Returns an absolute value of a + (-b)

Ungolfed version:

int n(int a, int b) {
return Math.abs(a + (-b));
}

• Wouldn't it fail for 0 and 0? – MatthewRock Mar 1 '17 at 23:19
• @MatthewRock didnt check that. I willfix it tomorrow – cookie Mar 1 '17 at 23:23
• Isn't a+(-b) equivalent to a-b? – Zacharý Sep 16 '17 at 13:41