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
Commented Feb 13, 2017 at 3:01
• Can the output have leading zeroes? Commented Feb 13, 2017 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? Commented Feb 13, 2017 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. :) Commented Feb 13, 2017 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. Commented Feb 13, 2017 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
Commented Feb 13, 2017 at 11:28
• @TomDevs Oh yea I totally forgot about currying and thanks for the output tip as well.
– user64039
Commented Feb 13, 2017 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 :-) Commented Feb 13, 2017 at 15:01
• I think that will break the IIFE Commented Feb 13, 2017 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. Commented Feb 13, 2017 at 16:21
• currying, i.e. a=>b=>a+b+1 is shorter. you then call it with f(1)(2) Commented Feb 13, 2017 at 19:55
• Does not work for inputs 1e53 and 0. Commented Aug 20, 2020 at 14:46

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. Commented Mar 8, 2017 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; Commented Feb 14, 2017 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! Commented Feb 26, 2017 at 18:57
• why not n(a){a=&a;}
– l4m2
Commented Dec 15, 2017 at 18:50
• @l4m2 The question requires 2 inputs Commented Dec 17, 2017 at 9:37
• n(a){a=&a;} main(a,b){return n(1,2);} works fine
– l4m2
Commented Dec 17, 2017 at 10:05
• Do you know why that works? Commented Dec 17, 2017 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+¡. Commented Mar 2, 2017 at 15:04 • @ZachGates OK thanks! Good luck – user63187 Commented Mar 2, 2017 at 15:13 • @ZachGates one I had was +R+! Then found the other way – user63187 Commented Mar 2, 2017 at 16:13 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. Commented Apr 1, 2017 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 naz, 56 bytes 6a8m2x1v1x1f1r3x1v2e0m1o0x1x2f2r3x1v3e0m1o0x1x3f1a1o0x1f  Takes two natural numbers as input, separated by a space. Explanation (with 0x commands removed) 6a8m2x1v # Set variable 1 equal to 48 ("0") 1x1f1r3x1v2e0m1o # Function 1 # Read the first byte of input, removing it from the input string # Jump to function 2 if it equals variable 1 # Otherwise, output 0 1x2f2r3x1v3e0m1o # Function 2 # Read the second byte that's still in the input string # Jump to function 3 if it equals variable 1 # Otherwise, output 0 1x3f1a1o # Function 3 # Output 1 1f # Call function 1  Flurry, 12 bytes []{<{}{}>}{}  Run example $ printf "0 0" | ./flurry -nib -c "[]{<{}{}>}{}"
73728
$printf "0 1" | ./flurry -nib -c "[]{<{}{}>}{}" 75264$ printf "0 11" | ./flurry -nib -c "[]{<{}{}>}{}"
3687936


Takes two numbers separated by single space from stdin in binary mode, and prints the return value as an integer.

The binary mode is the trick here. What the program does is to implicitly push all codepoints of stdin to the stack, and print the product of the entire stack.

Code explanation

// Pop (stack height + 1) times and compute the product;
// popping from empty stack gives I = 1
//     []     {<{}{}>}  {}
main = height times-pop pop

//          {   <{}  {}  >}
times-pop = \x.  x ∘ pop


Proof that this does not give a+b for any a b

Base case: The input of "0 0" gives 48 × 32 × 48 = 73728.

Inductive case:

• The codepoint of any printable ASCII is 32 or above, so adding a digit (which amplifies a+b by at most 10) amplifies the output by 32 or above.
• Adding 1 to an existing digit adds the product of all the codepoints except itself to the output, which is much greater than the digit value of the modified digit.

Therefore, the output grows much faster than the value of a+b, and they can never be equal.

For comparison, here is the program that computes a+b+1:

Flurry, 18 bytes

{}(<><<>()>)[{}{}]

$./flurry -nin -c "{}(<><<>()>)[{}{}]" 12 13 26$ ./flurry -nin -c "{}(<><<>()>)[{}{}]" 0 0
1
$./flurry -nin -c "{}(<><<>()>)[{}{}]" 0 10 11  // initial stack = a b // {} (<><<>()>) [{} {} ] main = pop (push succ) (pop pop) // b succ a = b succ (succ a) = b + succ a = a + b + 1  Haskell, 8 bytes (+).succ  Try it online! I'm certain this could be shorter but I haven't found a solution yet. 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
Commented Dec 17, 2017 at 10:09