# Test if two numbers are equal

## 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.
• 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 – James May 31 '17 at 20:29
• 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. – Rɪᴋᴇʀ May 31 '17 at 20:33
• @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". – CalculatorFeline May 31 '17 at 21:01
• @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. – ETHproductions May 31 '17 at 21:10
• 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. – Peter Cordes Jan 10 '18 at 4:20

# Kotlin, 39 30 bytes

fun f(x:Int,y:Int)=print(x==y)


Try it online!

• you could make this a lambda {x:Int,y:Int->print(x==y)} – 2xsaiko Jan 12 '18 at 13:34

## QBIC, 4 bytes

?:=:


This takes a and b in from the command line and prints -1 when equal, 0 when not.

Alternative 4-byter

?:-:


This prints the result of subtracting b from a and gives 0 for equals, and any other value else-wise.

# Perl 6, 4 bytes

*==*


Try it

This creates a WhateverCode lambda, Each * represents a parameter

# 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


# C, 20 bytes

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


# Lua, 18 bytes

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


Try it online!

# 09D, 13 bytes

310310412D301


Outputs 1 if the values are equal, otherwise 0

### Explanation:

310310412D301
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
0      ..from stack
1     ..to I/O (STDOUT)



## Java, 4136 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.

• @totallyhuman Thanks! Got a bit confused since the description said "2 decimal integers" – Mas May 31 '17 at 22:34
• 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. – Peter Cordes Jan 10 '18 at 2:06

# Triangular, 6 bytes

$.$%=<


Try it online!

Formats into this triangle:

  $.$
% = <


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

Pretty simple.

$read integer input = compare notepad to input % print notepad  Try it online! # 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  # 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  # TI-Basic, 3 bytes not(variance(Ans  Gives {1} as truthy value or {0} for falsy. -1 bytes thanks to lirtosiast! • not(variance(Ans – lirtosiast Nov 24 '18 at 4:09 • @lirtosiast Good tip, thanks! – Timtech Dec 5 '18 at 16:19 # 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. • 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? – anna328p Dec 3 '18 at 4:43
• Great! Gabriel Mills, try this !($args[0]-$args[1]) or $a,$b=$args;!($a-$b) or param($a,$b)!($a-$b) – mazzy Dec 3 '18 at 5:40 ## Caboose, 24 bytes print(input()==input());  TIO # 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. # Flurry, 30 bytes {}{{}{}}[{}{{{}}}[<>()]](){{}}  You can test it with the interpreter: $ for i in {0..5}; do
$for j in {0..5}; do$     ./Flurry -nin -c '{}{{}{}}[{}{{{}}}[<>()]](){{}}' $i$j
$done | xargs$ done
1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1


In Flurry, popping from the stack returns the I combinator (λa. a), which also happens to be the Church numeral representation for the number 1. Thus we can compute N != M using the following method:

• Push 0 to the stack.
• Push 1 to the stack N times.
• Pop from the stack M times and ignore the value.
• Pop from the stack and return the value.

This is how the program works conceptually, but we can combine the first two steps and the second two steps using a few tricks.

• {{}} represents the I combinator (1 = I = λa. a).
• {{{}}} is a function that pushes its argument to the stack and returns the I combinator (λa. (push a; λb. b))
• [<>()] represents zero (0 = S K = λab. b).
• By applying the input number to both of these terms, we obtain the expression n{{{}}}[<>()], which has the following semantics:
• If n > 1, push 0 to the stack, followed by n - 1 ones, and return 1.
• If n = 0, push nothing to the stack and return 0.
• {{}{}} is a function that takes an argument a, pops a value b from the stack, and returns ba. In this case, a and b are both guaranteed to be either zero or one, so it effectively returns 0 if (a, b) == (1, 0) and 1 otherwise.
• By applying the input number to this term, and to the result of the previous term, we obtain the expression n {{}{}} [m {{{}}} 0], which has the following semantics:
• If m = 0, [m {{{}}} 0] pushes nothing and returns 0. Since the stack is empty, {{}{}} always pops one, so its return value is always 1. Thus the entire expression is 0 if n = 0 and 1 otherwise.
• If m > 0, [m {{{}}} 0] pushes 0 followed by n - 1 ones and returns 1. Thus {{}{}} always returns the value popped from the stack, and n {{}{}} 1 pops n times and returns the last value popped. The entire expression is 0 if n = m and 1 otherwise.

The last step is to take the resulting number (representing whether the values are unequal) and negate it by applying it to () and {{}}.

# 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!

• 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. – Peter Cordes Jan 9 '18 at 13:24
• 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. – Peter Cordes Jan 9 '18 at 13:26

# ><>, 3 bytes

=n;


Try it online!

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

• Random post: You have 1111 reps now! – null Sep 27 '19 at 4:50
• And 1 silver badge, and 11 bronze badges! Gotta say, it really disincentivizes further activity. xD – squid Sep 27 '19 at 11:15
• If only you program with 1+... (Sorry for 1+-promoting) – null Sep 27 '19 at 11:20
• 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) – null Sep 27 '19 at 13:21
• I now have 666 reps... – null Sep 27 '19 at 13:21

# Clam, 5 4 bytes

p:rr


## Explanation

p    - Print...
r  - Next input
:   - Equal to
r - Next input


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