Notcalc (Calculate the wrong answer)

35

4

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

Julian Lachniet

Posted 2017-02-13T01:35:56.823

Reputation: 3 216

1Maybe we take the numbers as strings and output as a string? – xnor – 2017-02-13T03:01:52.907

1Can the output have leading zeroes? – user41805 – 2017-02-13T08:27:47.027

@Kritixi_Lithos Yes (allowed by default) – Julian Lachniet – 2017-02-13T11:38:21.220

1I presume overflows need to be taken into account, so the result of 2^32 -1 and 2 should not be negative, right? – adrianmp – 2017-02-13T12:28:07.890

@adrianmp Overflows are not necessary – Julian Lachniet – 2017-02-13T15:06:26.437

2Just 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 – 2017-02-13T17:11:00.917

6@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 – 2017-02-13T17:16:32.137

1@WheatWizard My apologies. I didn't know about that conversation. – peech – 2017-02-13T17:20:14.630

To have none of something is quite natural. Think of it that way. Anyways, if you look at the Wikipedia article, it seems that even though some people still exclude zero, the standards are moving towards including zero. (Programmers start counting at zero, the standard ISO 80000-2 includes zero, set theory uses zero as the empty set, etc). ℕ = {0,1, 2, …}; ℤ+= {1, 2, …}

– mbomb007 – 2017-02-16T17:53:56.060

"Die ganzen Zahlen hat der liebe Gott gemacht, alles andere ist Menschenwerk" ("God made the integers, all else is the work of man."). -Leopold Kronecker . – Kelly Lowder – 2017-02-17T15:26:07.930

Answers

36

RProgN, 4 3 1 Byte

Crossed out 4 is still 4 ;(

E

The most simple of solutions, compares if A and B are equal. Pushes true, which RProgN sees as 1, if they are the same, or false aka 0 otherwise.

Test Cases

0+0 = 1
1+0 = 0
0+1 = 0
1+1 = 1

Try it online!

ATaco

Posted 2017-02-13T01:35:56.823

Reputation: 7 898

23I just went down the rabbit hole with your crossed out link. I rate it <s>4</s>/4 – Rohan Jhunjhunwala – 2017-02-14T01:10:15.340

2@RohanJhunjhunwala hold my 4, I'm going in – Albert Renshaw – 2017-02-14T03:20:41.703

4̶4̶ <-- u+0336 (combining character) may be a better way to do it – Albert Renshaw – 2017-02-14T03:23:05.633

3

PSA: http://codegolf.stackexchange.com/questions/48100/very-simple-triangles/48101#comment113015_48101 Original crossed out thing

– Christopher – 2017-02-27T23:50:39.330

3@AlbertRenshaw the old PPCG crossed-out-4-a-roo? – Rɪᴋᴇʀ – 2017-03-07T16:36:48.490

15

Python, 13 bytes

[(0,0)].count

Try it online! Takes input as a tuple.

Using an object method for the function avoids the boilerplate of a lambda.

lambda a,b:a-~b   # 15 bytes

Here, the idea is to map (0,0) to 1 and everything else to 0. Since only 0+0 gives a sum of 0 among natural numbers, that always avoids matching the sum.

If one could output a Boolean here, which I find shady, a byte could be saved as

(0,0).__ge__

This checks if the input tuple is at most (0,0), which is only true for (0,0). In Python, True==1 and False==0. Even more shadily, outputting via exit code and treating that as a Python Boolen would save two bytes:

[(0,0)].pop

If string I/O is allowed and leading zeroes are OK, there's the 8-byte solution

'1'.join

This concatenates a1b, which is always bigger than a+b.

xnor

Posted 2017-02-13T01:35:56.823

Reputation: 115 687

1int.__eq__ for 10 bytes – Blue – 2017-02-13T12:48:31.647

@muddyfish Yeah, I saw suever's answer too, didn't think of using equality. It returns a bool though, which I think is iffy on a challenge that asks for a number output. – xnor – 2017-02-13T13:32:46.103

1IMO if it swims like a number and quacks like a number, it's reasonable to assume it's a number. – CalculatorFeline – 2017-06-19T17:47:38.387

15

Retina, 3 bytes

 
1

Try it online!

(The first line has a space before the newline. Stack Exchange isn't very good at showing trailing whitespace.)

Input is the numbers in decimal, separated by a space (e.g. 12 34). This program just changes the space to a 1, creating a number too large to be the sum of the input numbers (it necessarily has at least 2 more digits than either, and adding two numbers produces an output with no more than 1 digit more than the larger input).

user62131

Posted 2017-02-13T01:35:56.823

Reputation:

20 0 should also work. – Dennis – 2017-02-13T03:59:09.270

1@Dennis: I was wondering about that. 010 is considered to be an integer via basically all integer parsers. I can see a potential argument that 0 8 is invalid on the basis that 018 is considered invalid octal via some integer parsers (although it's considered to be decimal 18 by others). Note that this program is quite happy to handle leading zeroes in the input, treating them as decimal; and I've written programs that output leading zeroes for other questions without people seeing a problem. Is there a relevant meta post on the subject? – None – 2017-02-13T04:04:19.183

2Or . 1 if you don't want to return leading zeros yourself. – Martin Ender – 2017-02-13T14:48:08.763

@MartinEnder > but is a natural number – wizzwizz4 – 2017-02-14T19:43:53.617

@wizzwizz4 I'm not following. – Martin Ender – 2017-02-14T19:44:43.267

13

MATL, et al. 1 byte

=

Accepts two natural numbers as inputs and compares them. If they are equal, the output is 1 and if they not equal the output is 0. This is the same approach as @ATaco's solution.

Suever

Posted 2017-02-13T01:35:56.823

Reputation: 10 257

3The = solution also works in Jelly for 1 byte. I thought I'd mention it in the comments as it doesn't seem worth creating a separate answer for the trivial solution. – None – 2017-02-13T03:01:53.683

@ais523 Updated to include that. Thanks. – Suever – 2017-02-13T03:07:37.920

2

Also in Stacked. Try it online!

– Conor O'Brien – 2017-02-13T16:36:17.037

Can you add APL and J? – Adám – 2017-02-14T18:08:03.080

@Adám Sure thing. Do you have a TIO link that I can link to? – Suever – 2017-02-14T18:19:45.253

I think this post should be a community wiki instead – user41805 – 2017-02-15T09:47:24.470

@KritixiLithos Thanks. I meant to do that yesterday but got distracted. Updated now so that others can easily edit. – Suever – 2017-02-15T19:03:13.297

10

Javascript, 10 bytes

x=>y=>!x+y

Takes 2 numbers using currying syntax like so:

(x=>y=>!x+y)(0)(0) // 1

Malivil

Posted 2017-02-13T01:35:56.823

Reputation: 345

4Welcome to the site! :) – James – 2017-02-13T22:04:32.537

Thanks =) I've been reading challenges for a while, just trying to find a good place to start. – Malivil – 2017-02-14T13:52:01.473

9

Brain-Flak, 8 bytes

({}{}())

Try it online!

This is the most readable brain-flak answer I have ever written. :)

Explanation:

(      )    # Push the sum of all the following:
 {}         #   The first input
   {}       #   The second input
     ()     #   and one

Alternate solutions (also 8 bytes):

({}[]{})    # Sum + 1
([]{}{})    # Sum + 2

There's a bunch of other solutions that only work with positive numbers:

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

James

Posted 2017-02-13T01:35:56.823

Reputation: 54 537

9

Vim, 3 bytes/keystrokes

<C-a>gJ

Try it online!

Note that <C-a> is actually ctrl-a, which represents byte 0x01.

I love it when vim (which isn't even a programming language) can compete with golfing languages. :) Input comes in this format:

a
b

This simply increments the first number by one (This is the <C-a> part) and then joins the string representations of the two numbers together. As far as I can tell, this should never result in the sum.

James

Posted 2017-02-13T01:35:56.823

Reputation: 54 537

7

Jelly, 2 bytes

+‘

The + adds the two inputs together then the ' increments the answer by one

Try it online!

Christopher

Posted 2017-02-13T01:35:56.823

Reputation: 3 428

This answer makes me jelly. – MD XF – 2017-05-20T01:56:56.907

I bet it does :P – Christopher – 2017-05-20T19:34:33.503

Technically this is not (a+b)+1 but a+(b+1) because the dyad-monad chain fG is treated as f(a, G(b)). In this case it's the same thing but technically how it works is different :P – HyperNeutrino – 2018-05-17T12:29:02.957

6

TI-Basic, 3 bytes

not(max(Ans

Alternative solutions:

10^(sum(Ans         3 bytes @DestructibleWatermelon
not(sum(Ans         3 bytes
1+sum(Ans           4 bytes
Input :X=Y          5 bytes @ATaco
Input :X+not(Y      6 bytes
Input :not(X+Y      6 bytes
Input :10^(X+Y      6 bytes
Input :X+Y+1        7 bytes
Input :not(max(X,Y  7 bytes
Ans(1)=Ans(2        8 bytes
Ans(1)+not(Ans(2    9 bytes
not(Ans(1)+Ans(2    9 bytes

It's interesting that you made the question's examples in TI-Basic, but you forgot the shorter A=B (or maybe it was up to us to find out?)

Timtech

Posted 2017-02-13T01:35:56.823

Reputation: 12 038

1Nobody likes it when the OP posts a super short solution in the question, making it hard to beat. – mbomb007 – 2017-02-13T20:20:35.567

@mbomb007 I suppose, but those were only snippets and not full programs. Adding Prompt A,B: to them brings the byte count to eight bytes each. – Timtech – 2017-02-13T22:14:51.757

1@Timtech Exactly. I didn't want to give good answers as examples, I just wanted examples. – Julian Lachniet – 2017-02-15T11:57:34.407

@JulianLachniet I understand and appreciate that :) – Timtech – 2017-02-15T15:32:58.017

6

Brachylog, 2 bytes

+<

Try it online!

Explanation

+     The sum of the elements in the Input...
 <    ...is strictly less than the Output
      (implicitely label the output with an integer respecting this constraint)

This will always result in A+B+1, if Input = [A, B].

Fatalize

Posted 2017-02-13T01:35:56.823

Reputation: 32 976

5

Mathematica, 5 bytes

1+##&

Outputs the sum of the two arguments plus 1. For example, 1+##&[2,5] yields 8.

(Side note: Binomial almost works, although Binomial[1,0]=1 and Binomial[4,2]=6 are counterexamples; I think they're the only counterexamples, though.)

Greg Martin

Posted 2017-02-13T01:35:56.823

Reputation: 13 940

Pochhammer seems to be one better than Binomial. As far as I can tell only 1,0 fails. – Martin Ender – 2017-02-13T12:05:29.527

Ah, and KroneckerDelta works for all inputs (being the equivalent of the equality check in some of the esolangs). It's actually shorter to reimplement as Boole[#==#2]&, but I assume you were looking for a built-in that works as is. – Martin Ender – 2017-02-13T12:08:21.977

5

PHP, 17 bytes

<?=1-join($argv);

Run like this:

echo '<?=1-join($argv);' | php -- 0 0
> 1

Explanation

This just concatenates the arguments. The first argument (script name) contains -. So that results in a negative number, which I negate with the minus sign. Then I add 1, just in case the first input number is a 0 (0123 = 123).

aross

Posted 2017-02-13T01:35:56.823

Reputation: 1 583

5

Perl 6, 4 bytes

!*+*

A lambda (formed by Whatever-currying), that adds the boolean inverse (1 or 0) of the first argument to the second argument.

Try it online!

smls

Posted 2017-02-13T01:35:56.823

Reputation: 4 352

4

Turtlèd, 12 bytes

makes very large numbers

'1?:?:[1'0l]

Try it online!

Explanation:

'1                write one on the starting grid square
  ?:?:            take a number, move right that many (repeat)
      [1   ]      while not on a grid square with a one on it
        '0l       put a zero on that square, move left
[implicit output of grid]

It thus outputs 10**(x+y).

Destructible Lemon

Posted 2017-02-13T01:35:56.823

Reputation: 5 908

4

PHP, 19 bytes

1<?=max([0]+$argv);

user63956

Posted 2017-02-13T01:35:56.823

Reputation: 1 571

4

Java (OpenJDK 9), 10 bytes

a->b->a-~b

Try it online!

Pavel

Posted 2017-02-13T01:35:56.823

Reputation: 8 585

1With currying, you can spare a byte: a->b->a-~b. Also works with Java 8, any edition (so there's no need to specify the OpenJDK 9) – Olivier Grégoire – 2017-02-14T09:20:21.407

@OlivierGrégoire Java has started to look like JS now >_> – user41805 – 2017-02-14T09:34:11.597

@KritixiLithos Well... we had a hint this would happen for years: JavaScript ;-) – Olivier Grégoire – 2017-02-14T10:01:17.757

@KritixiLithos The specification for Java 9 has a section on 'ECMAScript 6 Compliance'. – Pavel – 2017-02-14T15:33:00.480

@OlivierGrégoire Yeah, but this submission was generates automatically, which is why the 9 was added. – Pavel – 2017-02-14T15:33:25.393

4

HODOR, 40 bytes (non-competing)

This is probably the shortest program Hodor's ever written!

This is what happens when you have nothing to do for a 2-week school holiday: produce a bunch of really easily coded joke languages that do absolutely nothing. Yay for school holidays!!!

Walder
Hodor?!
Hodor?!
Hodor HODOR!
HODOR!!!

Walder was Hodor's original name and so is needed to begin the program.

Hodor?! takes either a number from STDIN or a single character and sets the accumulator to the input

Hodor add 1 to the accumulator

HODOR! outputs the accumulator as a number

HODOR!!! kills Hodor! Noooooo!

This is the pseudo code:

Take input
Take input
Add 1 to sum(inputs)
Output value

caird coinheringaahing

Posted 2017-02-13T01:35:56.823

Reputation: 13 702

1

I think you need to come up with a different name for your language unless this is an interpreter of the pre-existing Hodor language created in 2015, which I'm fairly certain this isn't.

– mbomb007 – 2017-04-05T13:52:25.693

@mbomb007 No that isn't mine but there are languages with duplicate names. I know of two called 7 on this site (I just can't find them at the moment) – caird coinheringaahing – 2017-04-05T13:58:26.553

1

I'm pretty sure there's only one called 7, and it's this one. You could change the capitalization of the title for an easy fix, something like HODOR.

– mbomb007 – 2017-04-05T13:58:53.247

@mbomb007 mine is Hodor and theirs is hodor so that could be enough? – caird coinheringaahing – 2017-04-05T14:01:32.660

No, theirs has a capital H, as you can see from every time he uses the language name on his website. – mbomb007 – 2017-04-05T14:01:47.313

@mbomb007 If it must be done... – caird coinheringaahing – 2017-04-05T14:02:46.333

I think it'd be easier, in the event that we have a leaderboard, it would otherwise get confused between the two. – mbomb007 – 2017-04-05T14:03:29.110

Let us continue this discussion in chat.

– mbomb007 – 2017-04-05T14:05:28.630

3

SmileBASIC, 4 bytes

!A+B

not(A)+B
1+1=2 -> !1+1 -> 0+1=1
0+1=1 -> !0+1 -> 1+1=2

12Me21

Posted 2017-02-13T01:35:56.823

Reputation: 6 110

Out of curiosity, how does this support 2+1? – ATaco – 2017-02-13T01:53:09.600

22+1=3 -> !2+1 -> 0+1=1 – 12Me21 – 2017-02-13T01:54:35.803

3

MATLAB / Octave, 3 bytes

@eq

Accepts two inputs and checks for equality and yields 1 if they are equal and 0 otherwise.

Online Demo

Suever

Posted 2017-02-13T01:35:56.823

Reputation: 10 257

4Shouldn't this be @eq? That returns a function handle which can be used to evaluate to the desired function, while just eq is meaningless. – Sanchises – 2017-02-13T08:16:20.760

@Sanchises I've seen many answers go both ways: http://codegolf.stackexchange.com/questions/106149/compute-the-median/106152#106152. I'm not actually sure which is preferred.

– Suever – 2017-02-13T13:30:30.650

Hmmm. I should think this is more like a snippet, while an @ turns it into a valid language construct. But maybe I'm just being pedantic. – Sanchises – 2017-02-13T13:58:57.367

3

R, 13 bytes

sum(scan()+1)

Thanks to Jonathan Allan for his inputs !

Frédéric

Posted 2017-02-13T01:35:56.823

Reputation: 2 059

@JonathanAllan : You're right, I changed my answer. Thanks ! – Frédéric – 2017-02-13T07:06:30.673

OK, pretty sure 00 is the same as 0 though, maybe sep="1"? – Jonathan Allan – 2017-02-13T07:08:32.167

@JonathanAllan : damnit ! Thanks again ! – Frédéric – 2017-02-13T07:38:59.600

Looking at the Tips For Golfing In R it seems scan() should be fine, accepting a vector input, like this. But we can do one byte better with cat(sum(scan()+1)). Maybe there is shorter?

– Jonathan Allan – 2017-02-13T07:54:14.380

In this strategy, I don't think that cat is needed anymore, since we're no longer sticking numbers together. – Frédéric – 2017-02-13T08:08:27.137

1With the cat it is a full program, the alternative would be an unnamed function for the same byte cost function(a,b)a+b+1 – Jonathan Allan – 2017-02-13T08:10:46.657

3

C 26 24 19 bytes

f(c,d){return!c+d;}

Ungolfed version:

int f(int c,int d)
{
   return !c+d; 
}

I hope I got the specification right. Can definitely be shortened!?

@Pavel Thanks for saving 2 bytes

@Neil Thanks for your input.

Abel Tom

Posted 2017-02-13T01:35:56.823

Reputation: 1 150

1Do you need () around !c+d? – Pavel – 2017-02-13T07:48:52.300

@Pavel You're right, brackets were useless, updated! – Abel Tom – 2017-02-13T08:07:13.943

2Not 100% sure but I think you can remove the space in your return, like return!c+d; – Metoniem – 2017-02-13T08:50:39.300

Do you need the space after return? Do you need the int specification? – Neil – 2017-02-13T08:53:38.857

@Neil You're right they were both unnecessary. Updated. Sorry I come from the clean-code club. :) Have to get used to golfing in C. – Abel Tom – 2017-02-13T09:25:15.633

@Metoniem Huh, your comment didn't show up when I was commenting, sorry for stomping on you like that. – Neil – 2017-02-13T09:48:21.413

@Neil Haha that's okay! I wasn't even sure about it, you just confirmed. I only assumed it would work because it also does in C# :) – Metoniem – 2017-02-13T09:51:24.193

1Lose the return and instead assign it with something like c+=!d – Ahemone – 2017-02-13T10:22:10.140

Surely the ungolfed version should still have the int and spaces etc... – Neil – 2017-02-13T10:52:54.497

@Neil Thanks, will remember next time to leave the Ungolfed version clean. – Abel Tom – 2017-02-13T12:06:50.267

@Ahemone I don't think that's considered output though? – Albert Renshaw – 2017-02-14T03:31:38.453

@AlbertRenshaw While it's undefined and somewhat dependent on the calling convention the compiler uses and which registers used but from what I understand of GCC, on x86 at least, it will place any data it wishes to store in an offset position in memory in the same register as the return value so when the function exits with no explicit return the register designated to store the return value contains the last value that was stored somewhere in memory. – Ahemone – 2017-02-14T04:42:55.567

@Ahemone Could you provide a reference to this? I'm having a hard time reproducing this on any online C IDEs – Albert Renshaw – 2017-02-14T05:13:45.037

1

@AlbertRenshaw It's not something I'd rely on for portability but here are a couple of examples. I can't get it to work offline and it seems that it needs to be assigned to a non argument variable on TIO.. https://tio.run/nexus/c-gcc#RY1LCgIxDED3PUWoCK1GcEBXxZt0099AFw2ljhuHOXuNVRhISPLyQg4xzZkSvFXAqKG2TMus5PFpaWS0ZEkiLzEPRfdgSDn0eg0Pd/Jm6@U38iUwOjMSdUc0LH9xjMUXFJdJ6VXA/i3CCImkbnjXCOVfq5ombrRhu6Xl1QiuRmz9Aw

– Ahemone – 2017-02-14T06:44:56.370

@Ahemone wow thank you! Very impressive – Albert Renshaw – 2017-02-14T06:46:18.363

@Ahemone can you post your 14 byte solution as an answer please? ʕ•ᴥ•ʔ – Albert Renshaw – 2017-02-26T08:45:38.383

@AlbertRenshaw I have now done so with 13 bytes at http://codegolf.stackexchange.com/a/111339/64644 . AbelTom, I'm sorry for polluting your comments by promoting my answer.

– Ahemone – 2017-02-26T09:54:15.347

3

05AB1E, 1 byte

Q

Works the same as the RProgN answer.

Checks if a and b are the same. If so, print 1. Otherwise, print 0

Try it online!

Okx

Posted 2017-02-13T01:35:56.823

Reputation: 15 025

3¢ ( a.count(b) ) should also work for 1 byte. – Riley – 2017-02-13T16:54:46.647

@Riley you could post that as your own answer. – Okx – 2017-02-13T17:48:08.423

2It's not different enough to needs it's own answer. I thought we could just combine both 1 byte solutions into one answer. – Riley – 2017-02-13T17:49:43.453

3

PHP, 13 bytes; (17 REPL-less)

!max($argv)+0

Examples

[0,0] -> 1
[0,1] -> 0
[1,0] -> 0

For those without REPL use

<?=!max($argv)+0;

and run using

echo '<?=!max($argv)+0;' | php -- 0 0

mleko

Posted 2017-02-13T01:35:56.823

Reputation: 290

This answer is not valid because it doesn't output anything – aross – 2017-02-14T08:57:14.757

@aross If boolean cast was problem I updated my answer – mleko – 2017-02-14T11:29:20.533

Yes, you addressed both problems. The output would be true/false, not 1/0. Also, REPL :) – aross – 2017-02-14T11:46:32.180

3

Cubix, 9 8 bytes

u-~OII/@

Explanation

Expanded, this answer looks like this:

    u -
    ~ O
I I / @ . . . .
. . . . . . . .
    . .
    . .

The order of the instructions that are executed is II~-O@

II~-O@
I      # First input
   -   # Minus
 I~    # NOT(second input)
    O  # Output as integer
     @ # End program

Tested for all combinations of inputs where both are in the range 0-100.

Try it here.

Luke

Posted 2017-02-13T01:35:56.823

Reputation: 4 675

3

brainfuck, 12 bytes

Simple solution that outputs A+B+1.

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

Try it online

mbomb007

Posted 2017-02-13T01:35:56.823

Reputation: 21 944

Alternate answer (12 bytes): ,>,[-<++>]<. – Julian Lachniet – 2017-02-13T20:37:15.823

@JulianLachniet will that output A+2B? – george – 2017-03-08T13:37:58.460

A+2B hacked when B=0 – l4m2 – 2017-12-15T18:48:39.303

@mbomb007 I'm saying the ,>,[-<++>]<. solution – l4m2 – 2017-12-18T21:04:00.990

@JulianLachniet Yeah, that's not a valid answer because A+2B for input B=0, gives A. – mbomb007 – 2017-12-18T22:40:31.800

3

dc, 5 bytes

?1n+n

Try it online!

Input: Two natural numbers separated by a space on stdin.

Output: The digit 1 immediately followed by the sum of the two numbers, which is a number larger than the sum of the two numbers.

Example:

Input: 222 333

Output: 1555

Mitchell Spector

Posted 2017-02-13T01:35:56.823

Reputation: 3 392

3

APL - 4 Bytes

1++/

Takes array, sums its elements and adds one. Test:

 1++/1 2  
4
 1++/1 0
2

Antisthenes

Posted 2017-02-13T01:35:56.823

Reputation: 181

3

√ å ı ¥ ® Ï Ø ¿ , 4 bytes

II1_

II   Take 2 inputs and push to the stack
  1  Push 1 to the stack
   _ Push the sum of the stack

To output, add o to the end.

caird coinheringaahing

Posted 2017-02-13T01:35:56.823

Reputation: 13 702

is that supposed to say 4 bytes? – Taylor Scott – 2017-07-09T15:05:31.053

1@TaylorScott I don't know what you're talking about :) – caird coinheringaahing – 2017-07-09T15:52:49.110

Oh I must have been mistaken ;P – Taylor Scott – 2017-07-09T15:54:49.473

3

Hexagony, 7 bytes

?<.!?)@

Try it online!

Or in more readable format,

 ? <
. ! ?
 ) @

This beats the current Hexagony solution of 11 bytes.

Explanation:

If the first number is not 0, the program takes the following path:

Not 0

This reads the first number and branches right. Then it reads the second number, followed by wrapping and trying to read a third, but that doesn't exist so it reads 0. This is printed and the program terminated (note that if a>0, since b is non-negative a+b>0).

If the first number is 0, the program takes the following path to start with:

Is 0

This reads the first number and branches left. It hits the corner, taking the route from along the north-west edge because the number is 0, and reads the second number. It wraps, then increments the second number and prints.

Is still 0

It bounces against the <, printing the incremented second input again. It increments the value and takes the north-east edge again, but this time because the current edge a twice-incremented non-negative value which is definitely positive. It then tries to get a third input, but receives 0 instead.

Is still 0 some more

Finally it wraps and gets diverted by the arrow, then tries to read a fourth input and gets 0 again. It wraps and tries to read a fifth input and receives 0 for the last time. This it prints, and wraps to the @ and exits.

Note that b*(10^k+1)*10>0+b=b where k is the length of b in digits, so this works.

boboquack

Posted 2017-02-13T01:35:56.823

Reputation: 2 017

2

Billiards, 11 characters = 17 bytes

⇲
⇲
+
1
+
↥

Implements x + y + 1. Pretty elementary. It takes the inputs on two separate lines. (By the way, the language was modified slightly after the challenge, but only to suppress the prompt from inputting, not sure if this answer is still valid).

7 characters = 11 bytes, non-competing

This one is shorter but only possible after a new update of the language:

⇲
⇲
=
$

This uses x == y, which was shamelessly stolen from @ATaco's RProgN solution [ hope you don't mind (: ]. The $, on exit, outputs how many balls passed over it.

HyperNeutrino

Posted 2017-02-13T01:35:56.823

Reputation: 26 575

slightly after the language typo, also I think when the language had the input prompt, it would still be valid. I don't think output standards are that strict, and non-suppressible outputs are allowed I think – Destructible Lemon – 2017-02-13T02:12:19.377

@DestructibleWatermelon Oh, that was a weird typo. Thanks for the clarification. I actually modified the language, then came and saw the challenge, so I decided to add that note in there in case anyone decided to be picky about checking when the push was made to GitHub, but thank you for clarifying that. – HyperNeutrino – 2017-02-13T02:14:15.103

2

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

user41805

Posted 2017-02-13T01:35:56.823

Reputation: 16 320

2

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
}

Metoniem

Posted 2017-02-13T01:35:56.823

Reputation: 387

2

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

G B

Posted 2017-02-13T01:35:56.823

Reputation: 11 099

2

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

user64039

Posted 2017-02-13T01:35:56.823

Reputation:

1You 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 – 2017-02-13T11:28:12.920

@TomDevs Oh yea I totally forgot about currying and thanks for the output tip as well. – None – 2017-02-13T11:42:39.290

2

Pyke, 1 byte

q

Try it here!

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

Blue

Posted 2017-02-13T01:35:56.823

Reputation: 26 661

2

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

svarog

Posted 2017-02-13T01:35:56.823

Reputation: 131

You can save two bytes by removing the outer pair of parentheses :-) – ETHproductions – 2017-02-13T15:01:15.033

I think that will break the IIFE – svarog – 2017-02-13T15:03:49.117

2We 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 – 2017-02-13T16:21:25.947

1currying, i.e. a=>b=>a+b+1 is shorter. you then call it with f(1)(2) – FlipTack – 2017-02-13T19:55:59.137

2

QBIC, 8 bytes

a bit uninteresting:

::?a+b+1

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

steenbergh

Posted 2017-02-13T01:35:56.823

Reputation: 7 772

2

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.

Business Cat

Posted 2017-02-13T01:35:56.823

Reputation: 8 927

2

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

MickyT

Posted 2017-02-13T01:35:56.823

Reputation: 11 735

2

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

Koppany Horvath

Posted 2017-02-13T01:35:56.823

Reputation: 41

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 – 2017-03-08T14:38:24.337

2

Clojure, 11 bytes

#(+ % %2 1)

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

Carcigenicate

Posted 2017-02-13T01:35:56.823

Reputation: 3 295

2

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
 r    # read input character
  :   # 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.

MickyT

Posted 2017-02-13T01:35:56.823

Reputation: 11 735

2

Cheddar, 11 bytes

(a,b)->a-~b

Try it online!

Pavel

Posted 2017-02-13T01:35:56.823

Reputation: 8 585

2

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!

Business Cat

Posted 2017-02-13T01:35:56.823

Reputation: 8 927

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 – 2017-02-14T20:55:54.983

2

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.

Riley

Posted 2017-02-13T01:35:56.823

Reputation: 11 345

2

///, 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!

boboquack

Posted 2017-02-13T01:35:56.823

Reputation: 2 017

2

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!

Ahemone

Posted 2017-02-13T01:35:56.823

Reputation: 608

Very nice! I was trying to get less than 14 and couldn't! – Albert Renshaw – 2017-02-26T18:57:18.230

why not n(a){a=&a;} – l4m2 – 2017-12-15T18:50:53.627

@l4m2 The question requires 2 inputs – Ahemone – 2017-12-17T09:37:14.737

n(a){a=&a;} main(a,b){return n(1,2);} works fine – l4m2 – 2017-12-17T10:05:55.740

Do you know why that works? – Ahemone – 2017-12-17T10:25:17.097

2

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

Christopher

Posted 2017-02-13T01:35:56.823

Reputation: 3 428

You still need to output your result (use ! or ¡). Best alternative I've come up with so far is l+¡. – Zach Gates – 2017-03-02T15:04:37.870

@ZachGates OK thanks! Good luck – Christopher – 2017-03-02T15:13:18.660

@ZachGates one I had was +R+! Then found the other way – Christopher – 2017-03-02T16:13:02.463

2

PHP, 22 bytes

eval("echo $argn+1;");

A port of ConnorLSW´s answer. Run with echo "<a>+<b>" | php -R '<code>'.

Titus

Posted 2017-02-13T01:35:56.823

Reputation: 13 814

2

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.

iwaseatenbyagrue

Posted 2017-02-13T01:35:56.823

Reputation: 231

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 – 2017-04-01T11:59:59.377

2

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

user85052

Posted 2017-02-13T01:35:56.823

Reputation:

2

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

sporeball

Posted 2017-02-13T01:35:56.823

Reputation: 461

1

Lua, 25 bytes

x={...}print(x[1]+x[2]+1)

Try it online!

Just a trivial A+B+1 solution.

IDid

Posted 2017-02-13T01:35:56.823

Reputation: 101

1

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.

colsw

Posted 2017-02-13T01:35:56.823

Reputation: 3 195

1

Chaincode, 2 bytes

a+

Explanation:

a   #Adds two input values
 +  #Increment

Roman Gräf

Posted 2017-02-13T01:35:56.823

Reputation: 2 915

1

Labyrinth, 6 bytes

??+)!@

Try it online!

Takes two number inputs, prints their sum + 1.

SnoringFrog

Posted 2017-02-13T01:35:56.823

Reputation: 1 709

1

Scala, 26 Bytes

var n=(a:Int,b:Int)=>a+b+1

Michal

Posted 2017-02-13T01:35:56.823

Reputation: 209

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.

Socratic Phoenix

Posted 2017-02-13T01:35:56.823

Reputation: 1 629

1

C, 18 bytes

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

try it online

Albert Renshaw

Posted 2017-02-13T01:35:56.823

Reputation: 2 955

#define f(a)a== calling currying lol – l4m2 – 2017-12-17T10:09:33.423

1

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

PidgeyUsedGust

Posted 2017-02-13T01:35:56.823

Reputation: 631

1

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

cookie

Posted 2017-02-13T01:35:56.823

Reputation: 271

Wouldn't it fail for 0 and 0? – MatthewRock – 2017-03-01T23:19:19.607

@MatthewRock didnt check that. I willfix it tomorrow – cookie – 2017-03-01T23:23:16.467

Isn't a+(-b) equivalent to a-b? – Zacharý – 2017-09-16T13:41:51.887

1

ForceLang, 33 bytes

def a io.readnum()
io.write a+a+1

SuperJedi224

Posted 2017-02-13T01:35:56.823

Reputation: 11 342

Does this take two numbers as input? – Blue – 2017-02-26T12:55:05.467

@muddyfish Yes. – SuperJedi224 – 2017-02-26T12:59:14.890

1

Windows batch, 24 23 17 bytes

@cmd/cset/a%1+%21

Test cases:

Tested on Win10 64-bit

Foo\Bar\Baz>NotCalc.bat 1 55
552

Note: batch files are limited to 32-bit signed integer!

stevefestl

Posted 2017-02-13T01:35:56.823

Reputation: 539

1isn't 0+0 with a trailing 0 00, which is 0? – undergroundmonorail – 2017-03-31T20:58:44.723

Oh yeah. I forgot that – stevefestl – 2017-04-01T01:36:17.023

I tested it for you (also on Win7 64-bit). 1+55 returns 552. I don't understand the program well enough to explain why it returned that and not 561, but I tried some other inputs and got more weird results like 5+9=96. I'm not sure why that is, but my limited testing didn't find anything that outputs a correct sum... – undergroundmonorail – 2017-04-01T04:03:29.440

It adds a trailing one to 55 so it becomes 551, 1+551=552 and 9 became 91, 5+91=96 – stevefestl – 2017-04-01T05:18:43.180

1Oh, I see. I thought it was adding a 1 to the result. – undergroundmonorail – 2017-04-01T05:21:44.280

@undergroundmonorail can you help me test this code: @cmd set/a%11? – stevefestl – 2017-04-01T05:27:59.020

1

Cardinal, 7 bytes

%:+~:*.

Outputs sum + 1

Try it online!

fəˈnɛtɪk

Posted 2017-02-13T01:35:56.823

Reputation: 4 166

1

Melang (Non competing) 13 bytes

\n\n+\n+\n\ni

I wrote Melang for this challenge and decided that it works so might as well bring it here.

Adds the numbers inputted together and adds one. For more on the language and to try it out visit here.

Christopher

Posted 2017-02-13T01:35:56.823

Reputation: 3 428

Wait, those aren't literal newlines? – ASCII-only – 2017-04-10T09:30:15.093

@ascii nope! Literal newlines error my implementation due to the website restrictions – Christopher – 2017-04-11T01:33:18.710

How does it error in your implementation? – ASCII-only – 2017-04-11T01:35:29.567

@ascii the way string inputs are taken in the website I used to write it breaks it – Christopher – 2017-04-11T01:40:17.103

well that's a JS implementation limitation not a melang implementation limitation, you do know you can make it a Stack Snippet and it would work right? – ASCII-only – 2017-04-11T01:41:35.923

It is a esolang. Also I only have mobile (spring break) – Christopher – 2017-04-11T01:45:58.287

Let us continue this discussion in chat.

– ASCII-only – 2017-04-11T01:46:25.223

1

Haskell, 11 9 bytes

(succ.).(+)

Adds together and then adds 1

EDIT: Of course, if you want to go with the boring answer:

a#b=a+b+1

is 9 bytes.

Generic Display Name

Posted 2017-02-13T01:35:56.823

Reputation: 365

1Non pointfree a#b=1+a+b is two bytes shorter. – Laikoni – 2017-04-01T09:21:08.410

1

c++, 28 bytes

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

Try it here

Johan du Toit

Posted 2017-02-13T01:35:56.823

Reputation: 1 524

1

Japt, 3 bytes

NxÄ

Try it online


Explanation

N   :The array of all inputs
x   :Sum the array
Ä   :Add one to each element

Shaggy

Posted 2017-02-13T01:35:56.823

Reputation: 24 623

1

Aceto, 9 bytes

ir+1
ri+p

Super straightforward. Prints the sum of the two inputs and 1. If I can assume for the inputs to be on the stack already, there's a 5-byte solution:

1+
+p

L3viathan

Posted 2017-02-13T01:35:56.823

Reputation: 3 151

1

Braingolf, 3 bytes [non-competing]

g1+

Appends the inputs to eachother (ie 17, 4 becomes 174), then increments by 1.

Notable testcases:

[0, 0] becomes 00, becomes 01
[0, 1] becomes 01, becomes 02
[1, 0] becomes 10, becomes 11
[1, 1] becomes 11, becomes 12

Skidsdev

Posted 2017-02-13T01:35:56.823

Reputation: 9 656

00 is equivalent to 0+0 = 0 as noted in the comments for Windows Batch (among others) – Ephphatha – 2017-05-28T04:01:02.240

1

MarioLANG, 35 bytes

;
)
;
>[!(+:
"=#===
) -
+ (
! <
#="

Reads two inputs and puts them in differents cells (variables). Increments one and decrements the other until the second number is zero. Then adds one calculate the wrong answer.

user69335

Posted 2017-02-13T01:35:56.823

Reputation:

1

Underload, 23 bytes

((::)~*)~(~)~*a*^*(**)*

Takes input in the form of Church numerals on the stack and outputs to the stack.

Try it online!

Madison Silver

Posted 2017-02-13T01:35:56.823

Reputation: 139

1

Excel VBA, 13 Bytes

Anonymous VBE immediate window function that takes input from range [A1:B1] (... or really any range that is a subset of [1:1], I suppose) and outputs their sum +7

?[Sum(1:1)+7]

Taylor Scott

Posted 2017-02-13T01:35:56.823

Reputation: 6 709

1

Perl 5, 8 bytes

7 bytes of code + 1 flag (-p)

$_+=!<>

Try it online!

Xcali

Posted 2017-02-13T01:35:56.823

Reputation: 7 671

Pretty sure perl gets -p free. – MD XF – 2017-11-16T03:32:19.177

1

Implicit, 2 bytes

+.

Try it online!

+.   implicit input of two integers
+    add them
 .   and increment

= also works for 1 byte, but I added that to the existing list of =s.

MD XF

Posted 2017-02-13T01:35:56.823

Reputation: 11 605

1

Aceto, 6 bytes

rrJiIp
r reads input and puts on stack (x2)
J concatenates top 2 values
i makes it an integer
I increments it
p prints it

Try it online!

FantaC

Posted 2017-02-13T01:35:56.823

Reputation: 1 425

1

x86 opcode, 2 bytes

INC EDX
RET

input EAX and EDX, output EDX:EAX If D':A=D+A then D has to be zero, making the equation still not correct

x86 opcode __cdecl, 3 Bytes

MOV DL, 3
RET

l4m2

Posted 2017-02-13T01:35:56.823

Reputation: 5 985

0

GolfScript, 3 bytes

Input is to be taken as two separate lines. In GolfScript, a preceding 0 is allowed for numbers.

n/0

Try it online!

Explanation

# Two inputs taken with newlines
n/  # Split the input (separated by newlines) with newlines
  0 # Add a 0 to prevent a preceding 0
    # Implicit concatenation

GolfScript, 3 bytes

~+)

Try it online!

Explanation

~   # Evaluate the input
 +  # Add the two numbers
  ) # Increment the sum

user85052

Posted 2017-02-13T01:35:56.823

Reputation: