# 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

# Brachylog, 0 bytes

Try it online!

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

• The right tool for the job. – Adám Jan 9 '18 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!. – user41805 Jun 1 '17 at 6:29
• @Cowsquack doesn’t work anymore – Stan Strum Jan 11 '18 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!

# Brain-Flak, 26 bytes

Straight from the wiki.

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


Try it online!

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

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

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

^(.+)¶\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? – CalculatorFeline May 31 '17 at 20:55 • @CalculatorFeline The pilcrow (¶) counts as one byte in ISO 8859-1 encoding, so it's all the same. – Riley May 31 '17 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...) – Martin Ender Jun 1 '17 at 12:59 # Python 3, 10 bytes int.__eq__  Try it online! • Damn, 30 seconds too late – shooqie May 31 '17 at 20:27 • Please explain the downvote. Have you tested this? – Erik the Outgolfer Jun 1 '17 at 11:08 • I couldn't make it work in python 2, so I specified it to python 3 – Felipe Nardi Batista Jun 1 '17 at 14:19 # Japt, 2 bytes ¥V  Try it online # Cascade, 5 4 bytes #& =  Turns out I didn't need the second & due to wrapping Try it online! # 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. – steenbergh May 31 '17 at 22:47 • Also an answer for MATL – Suever May 31 '17 at 23:29 • Works in APL and J too. – Adám Jan 9 '18 at 14:19 # 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! ## 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. # 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. – kamoroso94 Jan 31 '18 at 14:31 # Hexagony, 20 bytes -4 Bytes thanks to Jo King by using conditional wrapping. ?}?".@!\!.!_1/@_-<~.  Try it online! More readable version:  ? } ? " . @ ! \ ! . ! _ 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! – Erik the Outgolfer Jan 31 '18 at 14:48 • +1 for ._. :P – anna328p Feb 1 '18 at 21:24 • 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 '18 at 15:12 ## Keg, 1 byte(SBCS on Keg wiki) =  ## Explanation: =# Test whether they are equal  • 1 byte – lyxal Nov 16 '19 at 8:07 # 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. – null Aug 21 '20 at 12:16

# JavaScript (ES6), 10 bytes

x=>y=>x==y


# 05AB1E, 1 byte

Q


Try it online!

# Ohm, 1 byte

E


Try it online!

Because = is too mainstream.

# Python 2, 15 bytes

lambda x,y:x==y


Try it online!

# OCaml, 3 bytes

(=)


Brackets are necessary, plain = is a syntax error

# Mathematica, 6 bytes

#==#2&

• Or you could do Equal or SameQ for 5 bytes each. – Not a tree Jun 1 '17 at 7:49

# Pyth, 2 bytes

qE


Try it here :)

# GolfScript, 2 bytes

~=


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.

# Go, 36 32 bytes

-4 bytes thanks to powelles.

func f(x,y int)bool{return x==y}


Try it online!

• You can group function inputs by type (x,y int) – powelles May 31 '17 at 20:44