# 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 May 31, 2017 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. May 31, 2017 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". May 31, 2017 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. May 31, 2017 at 21:10
• "Decimal" is not a correct way to describe a numeric type like C int. It only makes sense when talking about string representation of numbers, or with decimal floating point (en.wikipedia.org/wiki/Decimal_floating_point) where the bit pattern representing the number uses base 10, not base 2. Or maybe a BCD integer. IIRC, IBM's POWER architecture has decimal float support, which is useful for some financial stuff, but most architectures only have IEEE binary32 / binary64. But anyway, a numeric type is probably best described as a binary integer, or simply "an integer". Jan 10, 2018 at 2:22

# Brachylog, 0 bytes

Try it online!

One number from STDIN and one from command-line arguments.

• The right tool for the job.
Jan 9, 2018 at 14:17

# brainfuck, 45494137 34 bytes

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


Try it online!

Takes the two integers separated by a single null byte. Null bytes are falsy in BF and everything else is truthy, so this prints a single 0x01 byte for truthy and a single 0x00 for falsy.

This is my first time golfing in BF, so feel free to give me suggestions...

### Explanation

,[>,]       Read in everything from STDIN until the null byte is reached
>+          Move one space to the right and increment; this will be a flag telling us
the numbers are still equal
<<[<]>      Move back to the beginning of the input
[           For each character in the input:
<,          Move to the left and input a character
[->-<]      Subtract this char from the char at the same spot in the original number
>[>]        If this is not zero (there is a difference between the two characters)
move to the hole before the flag
>           Move one character to the right
If we're in the hole before the flag this moves us onto the flag;
the loop runs once more and deposits us two spots to the right
]           Endwhile
When the while loop finishes we will be one spot to the left of the flag
or already to the right if the program found a difference between the numbers
However: we will still be just to the left of the flag for cases like 24 vs 245
,           So we input another byte (the next digit of the second number or 0x00)
[>]         and move past the flag if it's non-zero
>.          Move right (onto the flag or past the flag) and output

• Here's a TIO link to see be able to the output of the program in hexbytes: Try it online!. Jun 1, 2017 at 6:29
• @Cowsquack doesn’t work anymore Jan 11, 2018 at 1:49

# ///, 9 bytes

//f///t/f


Try it online!

Prints a t if they are equal, otherwise prints f.

Since there is no way to take input in ///, it is hard-coded.

/NUM1/f//NUM2/t/f


Explanation:

With example inputs of 12 and 121213. (Should return false.)

1. Input. /12/f//121213/t/f
2. Replace other occurrences of the first number with f. /ff13/t/f
3. Replace the modified new number with a t. Since the modified string is not f, , f stays the same. f.
4. Output. f.

With example inputs of 501 and 501. (Should return true.)

1. Input. /501/f//501/t/f
2. Replace other occurrences of the first number with f. /f/t/f
3. Replace the modified new number with a t. Since the modified string is f,f changes to t.
4. Output. t.

Credit to @user202729 for coming up with the better approach!

• That's... actually really clever, it took me a minute to figure out how it works. May 31, 2017 at 21:55
• @ETHproductions Thanks! :) May 31, 2017 at 22:05
• Could you tell the rest of us? Jun 4, 2017 at 0:14
• @cairdcoinheringaahing Done, is that good? Jun 4, 2017 at 0:26
• 12 == 1212? tio.run/##K85JLM5ILf7/X9/QSF8fSBgapemX6Kf9/w8A I suggest tio.run/##K85JLM5ILf7/X9/QSD9NH0gC6RL9tP//AQ instead. Oct 4, 2017 at 12:37

# yup, 16 bytes

I struggled to find an esolang where this was non-trivial (and that was not already covered). I present to you, this:

**-{0~-}0~-|0~-#


Try it online!

This works as follows:

**-{0~-}0~-|0~-#
**                  take two inputs on the stack
-                 subtract them
{0~-}0~-         this is "absolute value":
{   }              while TOS is > 0
0~-               this is negate:
0                   push 0                 [TOS, 0]
~                  swap                   [0, TOS]
-                 subtract               [-TOS]
thus, this negates positive numbers
0~-         negate again to get a positive number
this maps equal numbers to 0 and unequal numbers to their
absolute differences
|        take ln(TOS). This gives -Infinity for equal numbers, and
some value >= 0 for other numbers.
0~-     negate. this gives Infinity for equal numbers, and a number <= 0
for unequal numbers
#    output as number


Now, {...} is yup's loop and is the closest thing to a condition. It repeats the inside so long as the TOS is positive and defined. Thus, any negative or 0 value is falsey, and any positive value is truthy. Infinity is truthy, being greater than 0.

# Brain-Flak, 26 bytes

Straight from the wiki.

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


Try it online!

• There is a shorter version that "results in 0 if they are equal some other number otherwise" ({}[{}]) Mar 1, 2023 at 4:26

# Verbosity, 507 503 bytes

Include<MetaFunctions>
Include<Output>
Include<Input>
Include<Integer>
Include<Boolean>
Input:DefineVariable<i; 0>
Output:DefineVariable<o; 0>
Boolean:DefineVariable<c; 0>
Boolean:DefineVariable<r; Boolean:ArgumentsAreEqual<c; a; b>>
Boolean:DefineVariable<q; Boolean:LogicalNot<c; r>>
Output:DisplayAsText<o; q>
DefineMain<> [
MetaFunctions:ExecuteScript<MetaFunctions@FILE>
]


Try it online!

Saved 4 bytes thanks to Mr. Xcoder

Haha, no-one shall lose to Verbosity! Outputs with a Boolean<> wrapper around the result. The Boolean:LogicalNot is required due to an ongoing bug with booleans.

The ungolfed version:

Include<MetaFunctions>
Include<Output>
Include<Input>
Include<Integer>
Include<Boolean>

Input:DefineVariable<STDIN; 0>
Output:DefineVariable<STDOUT; 0>
Boolean:DefineVariable<constant; 0>

Boolean:DefineVariable<result; Boolean:ArgumentsAreEqual<constant; FirstInput; SecondInput>>

Boolean:RedefineVariable<result; Boolean:LogicalNot<constant; result>>

Output:DisplayAsText<STDOUT; result>

DefineMain<> [
MetaFunctions:ExecuteScript<MetaFunctions@FILE>
]


Try it online!

• 503 bytes? Jan 13, 2018 at 14:42
• @Mr.Xcoder Yep, how did I miss that? Jan 13, 2018 at 14:44
• 480 bytes? Dec 13, 2022 at 20:27

# Retina, 9 bytes

^(.+)¶\1$ Counts the number of times the first line matches the second. Try it online! • Can't you use space separated inputs for -1 byte? May 31, 2017 at 20:55 • @CalculatorFeline The pilcrow (¶) counts as one byte in ISO 8859-1 encoding, so it's all the same. May 31, 2017 at 20:58 • Deduplication stages are really helpful when it comes to equality. (But to be honest, even I forget that they exist half of the time...) Jun 1, 2017 at 12:59 ## Retina, 5 bytes Byte count assumes ISO 8859-1 encoding. D ¶$


Try it online!

### Explanation

D


Deduplicate with the implicit regex .+, i.e. if the two lines are identical, clear the second one (the separating linefeed remains though).

¶$ Try to match a linefeed followed by the end of the string. This is only possible if the first stage cleared the second line, i.e. if the two numbers were equal. # Python 3, 10 bytes int.__eq__  Try it online! • Damn, 30 seconds too late May 31, 2017 at 20:27 • Please explain the downvote. Have you tested this? Jun 1, 2017 at 11:08 • I couldn't make it work in python 2, so I specified it to python 3 Jun 1, 2017 at 14:19 # Japt, 2 bytes ¥V  Try it online ## 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" – svp May 31, 2017 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. Jan 10, 2018 at 2:06 # TI-BASIC, 13 bytes Prompt A,B If A=B Disp 1 Else Disp 0  Pretty self-explanatory. Prompts for two numbers and prints 1 if they are euqal, 0 otherwise. • You can shorten this to 8 bytes with Prompt A,B:A=B since the result of the = operator is 0 or 1 and will be implicitly displayed at the end of the program. Jan 31, 2018 at 14:31 # Cascade, 5 4 bytes #& =  Turns out I didn't need the second & due to wrapping Try it online! # Flurry-nin, 134 bytes <<>[(<<>()>)<<>[({}){}]>][<><<>[<>{{}}]()>]()()[<><<>()>]>({})[<><<>(){}>[()[<><<>()>]]]{{}{<{}{()[<>{}[<><<>()>]]}>}{{}(<>()){}}()}{}  ### Run example $ pgm="..." # the program above
$./flurry -nin -c$pgm 0 0
1
$./flurry -nin -c$pgm 123 45
0
$./flurry -nin -c$pgm 123 123
1


There is no task that is trivial in every language. Seriously.

Since Flurry's only representation of a number is Church numeral, this program takes only non-negative integers as input. Outputs 1 if two Church numerals represent the same number, 0 otherwise.

Implements the following function:

// (n+1-m) * (m+1-n), where a-b gives zero if a < b
// This gives 1 when m==n (both sides of * are 1)
// and 0 otherwise (one side is 0)
main = (\npm. <SK> (m p (succ n)) (n p (succ m))) n pred m

// succ n = n + 1
succ = S<SK>

// pred n = n - 1 (pred 0 = 0); implemented using pair construct
next-pair-helper = \fmn. f n (succ n) = \fm. S f succ = \f. K(S f succ)
= {()[<>{}[<><<>()>]]}
next-pair = \p. <p next-pair-helper>
= {<{}{()[<>{}[<><<>()>]]}>}
pred = \n. n next-pair zero-pair K
= {{}{<{}{()[<>{}[<><<>()>]]}>}{{}(<>()){}}()}

• It's not trivial in 1+, though. Aug 21, 2020 at 12:16

# Jelly, 1 byte

=


Try it online!

Explanation:

= Takes two arguments and returns a 1 if they are equal, and a 0 if they are not.
Implicit print.

• Alternatively, e tests for equality, and _ will subtract the input values from one another, yielding 0 for equals and any other value for different number. May 31, 2017 at 22:47
• Also an answer for MATL May 31, 2017 at 23:29
• Works in APL and J too.
Jan 9, 2018 at 14:19

# Ohm, 1 byte

E


Try it online!

Because = is too mainstream.

# OCaml, 3 bytes

(=)


Brackets are necessary, plain = is a syntax error

# sed, 14 bytes

Includes +1 for -r

s/^(.+),\1$//  sed doesn't have truthy/falsy values, so I use the empty string as truty and everything else as falsy. This make sense because /^$/ is the simplest (fully matching) if statement.

Try it online!

(==)


Try it online! (The function has to be named)

# JavaScript (ES6), 12 bytes

x=>y=>!(x-y)


Because 0 is false and all other numbers are true in JavaScript, if x-y equals 0, a not ! of that 0 will return true, and a not ! of any other number will return false. Two bytes longer than simple comparison x==y as shown in @Shaggy's answer.

## MSM, 31 bytes

'?ddF',',',.....T',',':'?....':


MSM is stack based, so the two input numbers are expected to be on top of the stack, i.e. on the right of the string. MSM has neither numbers nor booleans so we are free to choose a (reasonable) representation:

T      True
F      False
123    numbers are just sequences of ascii digits. There's no literal
representation in MSM source code, so you have to construct them
digit by digit:  321.. -> 123 (remember: . is concatenation)


TIO doesn't support MSM out of the box, so I've included the JS interpreter from the esolang page.

Try it online!

How it works: (I use a and b for the two numbers on the stack).

Excerpt from the MSM command reference:

'   quote, push next char on the stack, even if it is a command
?   skip next command if the two top elements of the stack are equal
,   drop
:   expand string at top of the stack and push each char of it on the stack
.   concatenate two top elements

everything else is pushed


Stack trace:

' ? d d F ' , ' , ' , . . . . . T ' , ' , ' : ' ? . . . . ' : a b
d d F ' , ' , ' , . . . . . T ' , ' , ' : ' ? . . . . ' : a b ?


The next 6 chars are pushed on the stack and concatenated with 5 dots

T ' , ' , ' : ' ? . . . . ' : a b ? ,,,Fdd


The next 5 chars are pushed on the stack and concatenated with 4 dots

' : a b ? ,,,Fdd ?:,,T


: and the two numbers are pushed

? ,,,Fdd ?:,,T : a b


Now it gets interesting. If the two numbers are equal, ,,,Fdd is skipped

?:,,T : a b           -- ?:,,T as a whole is not a command, so it's pushed
: a b ?:,,T           -- expand
a b ? : , , T         -- push a b
? : , , T a b         -- a b are still equal, so skip :
, , T a b             -- drop a b
T                     -- MSM stops, output is True


If the two numbers are not equal, don't skip ,,,Fdd, but push it:

,,,Fdd ?:,,T : a b
: a b ,,,Fdd ?:,,T    -- expand
a b ,,,Fdd ? : , , T  -- push up to ?
? : , , T a b ,,,Fdd  -- number b is never equal to ,,,Fdd so expand
, , T a b , , , F d d -- drop two dummy values
T a b , , , F         -- push T a b
, , , F T a b         -- drop b a T
F                     -- stop


# Cubix, 11 bytes

O0O1II-!//@


Try it online!

This was harder than expected. Outputs 0 for falsy and 10 for truthy.

# Hexagony, 20 bytes

-4 Bytes thanks to Jo King by using conditional wrapping.

?}?".@!\!.!_1/@_-<~.


Try it online!

   ? } ? "
. @ ! \ !
. ! _ 1 / @
_ - < ~ . . .
. . . . . .
. . . . .
. . . .


Prints 0 for truthy and 1 for falsy.
There's a no-op at the end to keep it at a sidelength of 4.

It might be possible to reduce the sidelength by one and safe a few more bytes.

If I can print 0 for truthy and anything else for falsy, this would be a valid solution aswell:

  ? } ?
/ - ! @
" / . . .
. . . .
. . .


This is basically just subtraction and seems like cheating to me.

• Welcome to PPCG! Jan 31, 2018 at 14:48
• 20 bytes by using the built-in branching instead of another <. Technically it's 19 bytes, but an extra . is needed to keep it side length 4. I'll have a look into a side length 3 version
– Jo King
Feb 14, 2018 at 15:12

# 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


## Caboose, 24 bytes

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


TIO

## Keg, 1 byte(SBCS on Keg wiki)

=


## Explanation:

=# Test whether they are equal

• 1 byte Nov 16, 2019 at 8:07

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

# JavaScript (ES6), 10 bytes

x=>y=>x==y


# 05AB1E, 1 byte

Q


Try it online!

# Python 2, 15 bytes

lambda x,y:x==y


Try it online!