-24
\$\begingroup\$

Challenge

  • Input two integers.
    • Integer I/O must be decimal.
  • If the integers are equal, output a truthy value.
  • Otherwise, output a falsy value.

Clarifications

  • You will never receive non-integer inputs.
  • You will never receive an input that is outside the bounds [-2³¹, 2³¹).

Rules

  • Standard loopholes are disallowed.
  • This is . Shortest answer wins, but will not be selected.
\$\endgroup\$
  • 18
    \$\begingroup\$ I can't tell you the reason for the other downvotes, but mine is because I firmly believe that trivial questions like this are bad for the site. -- Peter Taylor \$\endgroup\$ – DJMcMayhem May 31 '17 at 20:29
  • 6
    \$\begingroup\$ A reminder: as this is ridiculously trivial in most languages, please vote according to difficulty. Just because it's a 1 byte builtin in some golfing languages doesn't mean those answers are better than well-golfed longer solutions in, say, Brain-Flak. \$\endgroup\$ – Rɪᴋᴇʀ May 31 '17 at 20:33
  • 5
    \$\begingroup\$ @All downvoters: If you're downvoting this then you have to downvote the add two numbers challenge and the multiply two numbers challenge too because they're "too trivial". \$\endgroup\$ – CalculatorFeline May 31 '17 at 21:01
  • 5
    \$\begingroup\$ @CalculatorFeline But not all trivial challenges are the same level of trivial. In most languages without built-ins to add two numbers or check for equality (especially those without numerical input), I would expect the equality check to be easier to implement. Example: my BF equality check is 45 bytes, while the shortest BF addition program is 224 bytes. \$\endgroup\$ – ETHproductions May 31 '17 at 21:10
  • 2
    \$\begingroup\$ So are you trying to rule out a C function like int f(int a, int b){ return a==b;}? Because int in C represents numbers with base-2 bit-patterns, not decimal. (The details are implementation-defined, but there are enough requirements in the C standard that I don't think an implementation could legally choose a BCD (binary-coded-decimal) representation. At least not for unsigned char.) I think you're getting mixed up by source code that looks like int a = 1234;. That uses a decimal representation in the source, but not in the program. int a=0x4d2; is identical to 1234. \$\endgroup\$ – Peter Cordes Jan 10 '18 at 4:20

54 Answers 54

1
\$\begingroup\$

Perl 6, 4 bytes

*==*

Try it

This creates a WhateverCode lambda, Each * represents a parameter

\$\endgroup\$
1
\$\begingroup\$

Braingolf, 4 bytes

e1:0

Outputs 1 if inputs are equal, otherwise 0

Explanation:

e1:0  Implicit input to stack
e     If last 2 items are equal..
 1    ..push 1 to stack
  :   else
   0  ..push 0 to stack
      Implicit endif
      Implicit output of last item on stack
\$\endgroup\$
1
\$\begingroup\$

C, 20 bytes

f(a,b){return a==b;}
\$\endgroup\$
1
\$\begingroup\$

Lua, 18 bytes

a,b=...print(a==b)

Try it online!

\$\endgroup\$
1
\$\begingroup\$

09D, 13 bytes

310310412D301

Outputs 1 if the values are equal, otherwise 0

Explanation:

310310412D301
3                 Read..
 1                ..from I/O (STDIN)
  0               ..to stack
   310            Read 2nd input as above
      4           Apply math function...
       12D        ..isEqual, pop both items and push a 1
                     if they are equal, otherwise push a 0
          3       Read..
           0      ..from stack
            1     ..to I/O (STDOUT)
\$\endgroup\$
1
\$\begingroup\$

Java, 41 36 12 bytes

-4 bytes thanks to @totallyhuman - Changed floats to ints

-1 byte by removing space between second method argument and comma.

-24 by converting the whole program to a lambda (woo).

(i,j)->i==j;

Takes the form of a java.util.function.BiFunction< Boolean, Integer, Integer > using an expression lambda.

\$\endgroup\$
  • 1
    \$\begingroup\$ @totallyhuman Thanks! Got a bit confused since the description said "2 decimal integers" \$\endgroup\$ – Mas May 31 '17 at 22:34
  • \$\begingroup\$ float isn't decimal either; it's IEEE binary32. "decimal" is a stupid way of describing binary integers. It only makes sense when talking about their string representation, or with decimal floating point (en.wikipedia.org/wiki/Decimal_floating_point), which isn't provided in hardware by most FPUs. IIRC, IBM's POWER architecture has decimal float support, which is useful for some financial stuff. \$\endgroup\$ – Peter Cordes Jan 10 '18 at 2:06
1
\$\begingroup\$

Triangular, 6 bytes

$.$%=<

Try it online!

Formats into this triangle:

  $
 . $
% = <

Commands executed (without no-ops or directionals): $$=%

Pretty simple.

  • $ - read input as integer
  • = - compare top two stack values for equality
  • % - print result
\$\endgroup\$
1
\$\begingroup\$

Decimal, 13 bytes

81D81D412D301

Pretty simple. Ungolfed:

81D  ; builtin - read INT to stack
81D  ; builtin - read INT to stack
412D ; compare for equality
301  ; print to STDOUT

Try it online!

\$\endgroup\$
1
\$\begingroup\$

dc, 12 9 bytes

[1]sF=F0+

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Add++, 3 bytes

L,=

Try it online!

Yay for lambda functions!

\$\endgroup\$
1
\$\begingroup\$

Triangularity, 17 bytes

..)..
.I)1.
I=...

Try it online!

Triangularity, 17 bytes

..)..
.D@I.
sI=..

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Noether, 4 bytes

II=P

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Cubically, 8 5 bytes

$:$=%

Explanation:

$      read integer input
 :     set notepad to input
  $    read integer input
   =   compare notepad to input
    %  print notepad

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Whitespace, 60 bytes

[S S S N
_Push_0][S N
S _Duplicate_0][S N
S _Duplicate_0][T   N
T   T   _Read_STDIN_as_integer][T   T   T   _Retrieve][S S S T  N
_Push_1][S N
S _Duplicate_1][T   N
T   T   _Read_STDIN_as_integer][T   T   T   _Retrieve][T    S S T   _Subtract][N
T   S N
_If_0_Jump_to_Label_EQUAL][T    N
S T _Print_as_integer][N
N
N
_Exit_program][N
S S N
_Create_Label_EQUAL][S S S T    N
_Push_1][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 new-lines only).

Outputs 1/0 as truthy/falsey values. 3 bytes could be saved by removing NNN if 1/01 as truthy/falsey values are allowed.

Pseudo-code:

Integer i = STDIN as number
Integer j = STDIN as number
If(i == j):
  Call function EQUAL()
Print 0 to STDOUT
Exit program

function EQUAL:
  Print 1 to STDOUT
  Exit automatically with error
\$\endgroup\$
1
\$\begingroup\$

Python 2 - 15 bytes

lambda a,b:a==b

Like this:

def equality(a, b): Declare a function
    return a == b   Return True if equal, False if not
\$\endgroup\$
1
\$\begingroup\$

TI-Basic, 3 bytes

not(variance(Ans

Gives {1} as truthy value or {0} for falsy. -1 bytes thanks to lirtosiast!

\$\endgroup\$
  • \$\begingroup\$ not(variance(Ans \$\endgroup\$ – lirtosiast Nov 24 '18 at 4:09
  • \$\begingroup\$ @lirtosiast Good tip, thanks! \$\endgroup\$ – Timtech Dec 5 '18 at 16:19
1
\$\begingroup\$

PowerShell, 36 20 bytes

-16 bytes thanks to @mazzy (Basically their answer!)

!($args[0]-$args[1])

Try it online!

Simple. Takes arguments from commandline arguments.

\$\endgroup\$
  • \$\begingroup\$ I don't know much about powershell, but aren't you using more bytes to shorten $args to $a than you would be if you just wrote $args twice? \$\endgroup\$ – dkudriavtsev Dec 3 '18 at 4:43
  • \$\begingroup\$ Great! Gabriel Mills, try this !($args[0]-$args[1]) or $a,$b=$args;!($a-$b) or param($a,$b)!($a-$b) \$\endgroup\$ – mazzy Dec 3 '18 at 5:40
1
\$\begingroup\$

Keg, 3 bytes(SBCS on Keg wiki)

¿¿=

Explanation:

¿¿#  Two integer inputs
  =# Test whether they are equal
\$\endgroup\$
0
\$\begingroup\$

x86_64 machine language on Linux, 8 bytes

0:   31 c0                   xor    %eax,%eax
2:   39 f7                   cmp    %esi,%edi
4:   0f 94 c0                sete   %al
7:   c3                      retq

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Why are you bothering to return a 64 or 32-bit integer truth value? The x86-64 SysV calling convention (used on Linux) only requires bool return values to be in the low 8 bits; the remaining bits of rax are allowed to hold garbage. The only reason you (or gcc) would xor-zero eax would be for performance reasons to avoid a potential false dependency. \$\endgroup\$ – Peter Cordes Jan 9 '18 at 13:24
  • \$\begingroup\$ In assembly language, you should choose your calling convention to optimize for the problem. For example, you should return the compare result in ZF (so ZF=1 means equal). Then the whole function is only 4 bytes. \$\endgroup\$ – Peter Cordes Jan 9 '18 at 13:26
0
\$\begingroup\$

><>, 3 bytes

=n;

Try it online!

Takes command line arguments.
I feel unclean posting an answer to this one..

\$\endgroup\$
  • 1
    \$\begingroup\$ Random post: You have 1111 reps now! \$\endgroup\$ – HighlyRadioactive Sep 27 at 4:50
  • \$\begingroup\$ And 1 silver badge, and 11 bronze badges! Gotta say, it really disincentivizes further activity. xD \$\endgroup\$ – squid Sep 27 at 11:15
  • \$\begingroup\$ If only you program with 1+... (Sorry for 1+-promoting) \$\endgroup\$ – HighlyRadioactive Sep 27 at 11:20
  • \$\begingroup\$ Also, you can't stop people from upvoting your awesome answers! (I won't upvote this answer despite it being awesome and written in one of my favorite answer, though, to preserve 1,111) \$\endgroup\$ – HighlyRadioactive Sep 27 at 13:21
  • \$\begingroup\$ I now have 666 reps... \$\endgroup\$ – HighlyRadioactive Sep 27 at 13:21
0
\$\begingroup\$

Clam, 5 4 bytes

p:rr

Explanation

p    - Print...
  r  - Next input
 :   - Equal to
   r - Next input
\$\endgroup\$
0
\$\begingroup\$

C, 19 bytes

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

Try it online!

C, 18 bytes

#define f(a,b) a-b

Try it online!

"Truthy" value is 0 and "Falsy" value is anything but.

\$\endgroup\$
0
\$\begingroup\$

Caboose, 24 bytes

print(input()==input());

TIO

\$\endgroup\$
0
\$\begingroup\$

1+, 10 bytes

."."\</<*:

This is likely to be ungolfed: tell me if there's a better approach.

Explanation:

First, I'll name the two input A and B.

."." pushes A, duplicate it, pushes B, duplicate it. So now the stack is: A A B B.

\ rotates the stack, so the stack is now B A A B.

</<* Pushes A <= B, move it to the bottom of the stack, and pushes B <= A, then multiply them, as they are both boolean, this is equivalent to the and operation.

: Outputs the result.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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