-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\$
  • 19
    \$\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

16
\$\begingroup\$

Brachylog, 0 bytes

Try it online!

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

\$\endgroup\$
  • 2
    \$\begingroup\$ The right tool for the job. \$\endgroup\$ – Adám Jan 9 '18 at 14:17
14
\$\begingroup\$

brainfuck, 45 49 41 37 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
\$\endgroup\$
  • \$\begingroup\$ Here's a TIO link to see be able to the output of the program in hexbytes: Try it online!. \$\endgroup\$ – Kritixi Lithos Jun 1 '17 at 6:29
  • \$\begingroup\$ @Cowsquack doesn’t work anymore \$\endgroup\$ – Stan Strum Jan 11 '18 at 1:49
8
\$\begingroup\$

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

\$\endgroup\$
6
\$\begingroup\$

Brain-Flak, 26 bytes

Straight from the wiki.
Please don't upvote trivial answers.

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

Try it online!

\$\endgroup\$
6
\$\begingroup\$

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.

\$\endgroup\$
4
\$\begingroup\$

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.

\$\endgroup\$
4
\$\begingroup\$

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>
Integer:DefineVariable<a; Input:ReadEvaluatedLineFromInput<i>>
Integer:DefineVariable<b; Input:ReadEvaluatedLineFromInput<i>>
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>

Integer:DefineVariable<FirstInput; Input:ReadEvaluatedLineFromInput<STDIN>>
Integer:DefineVariable<SecondInput; Input:ReadEvaluatedLineFromInput<STDIN>>
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!

\$\endgroup\$
3
\$\begingroup\$

Retina, 9 bytes

^(.+)¶\1$

Counts the number of times the first line matches the second.

Try it online!

\$\endgroup\$
3
\$\begingroup\$

Python 3, 10 bytes

int.__eq__

Try it online!

\$\endgroup\$
  • 1
    \$\begingroup\$ Damn, 30 seconds too late \$\endgroup\$ – shooqie May 31 '17 at 20:27
  • \$\begingroup\$ Please explain the downvote. Have you tested this? \$\endgroup\$ – Erik the Outgolfer Jun 1 '17 at 11:08
  • \$\begingroup\$ I couldn't make it work in python 2, so I specified it to python 3 \$\endgroup\$ – Felipe Nardi Batista Jun 1 '17 at 14:19
3
\$\begingroup\$

Japt, 2 bytes

¥V

Try it online

\$\endgroup\$
2
\$\begingroup\$

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.
\$\endgroup\$
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – steenbergh May 31 '17 at 22:47
  • 1
    \$\begingroup\$ Also an answer for MATL \$\endgroup\$ – Suever May 31 '17 at 23:29
  • \$\begingroup\$ Works in APL and J too. \$\endgroup\$ – Adám Jan 9 '18 at 14:19
2
\$\begingroup\$

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!

\$\endgroup\$
2
\$\begingroup\$

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    
\$\endgroup\$
2
\$\begingroup\$

Cubix, 11 bytes

O0O1II-!//@

Try it online!

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

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – kamoroso94 Jan 31 '18 at 14:31
2
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to PPCG! \$\endgroup\$ – Erik the Outgolfer Jan 31 '18 at 14:48
  • \$\begingroup\$ +1 for ._. :P \$\endgroup\$ – dkudriavtsev Feb 1 '18 at 21:24
  • \$\begingroup\$ 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 \$\endgroup\$ – Jo King Feb 14 '18 at 15:12
2
\$\begingroup\$

Cascade, 5 4 bytes

#&
=

Turns out I didn't need the second & due to wrapping

Try it online!

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

JavaScript (ES6), 10 bytes

x=>y=>x==y
\$\endgroup\$
1
\$\begingroup\$

05AB1E, 1 byte

Q

Try it online!

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

Ohm, 1 byte

E

Try it online!

Because = is too mainstream.

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

Python 2, 15 bytes

lambda x,y:x==y

Try it online!

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

OCaml, 3 bytes

(=)

Brackets are necessary, plain = is a syntax error

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

Mathematica, 6 bytes

#==#2&
\$\endgroup\$
  • \$\begingroup\$ Or you could do Equal or SameQ for 5 bytes each. \$\endgroup\$ – Not a tree Jun 1 '17 at 7:49
1
\$\begingroup\$

Pyth, 2 bytes

qE

Try it here :)

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

GolfScript, 2 bytes

~=

Try it online!

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

Haskell, 4 bytes

(==)

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

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

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.

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

Go, 36 32 bytes

-4 bytes thanks to powelles.

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

Try it online!

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

Kotlin, 39 30 bytes

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

Try it online!

\$\endgroup\$
  • \$\begingroup\$ you could make this a lambda {x:Int,y:Int->print(x==y)} \$\endgroup\$ – therealfarfetchd Jan 12 '18 at 13:34
1
\$\begingroup\$

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.

\$\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.