g | x | w | all
Bytes Lang Time Link
035Raku Perl 6 rakudo250321T160331Zxrs
039Tcl190116T164923Zsergiol
230Bespoke250410T103853ZJosiah W
034AWK250227T190829Zxrs
049Janet250320T111010Zxigoi
092SAKO250319T081445ZAcrimori
019APLNARS250228T135404ZRosario
nan250222T021638ZRARE Kpo
028Desmos250222T010419ZDesmosEn
008Vyxal220705T195620ZnaffetS
033*><>220705T193028ZBee H.
037Factor220309T005529Zchunes
039x86 machine code190116T191551Zuser3604
040Factor210218T163530Zuser
015Pyth210302T032447ZScott
010Vyxal210301T130021Zuser1009
2120x8616 machine code190117T044505Z640KB
012Pyth201123T022917ZScott
090Desmos201121T211820ZAiden Ch
030Haskell201014T212519ZBenji
007Jelly190116T162252ZDennis
008Brachylog190216T042218ZDLosc
027Runic Enchantments190116T193537ZDraco18s
2670Pascal FPC190120T172459ZDessy St
038Ruby >=1.9190128T041623ZCG One H
034Ruby190120T115252ZJatin Dh
038APLNARS 19 chars190123T100824Zuser5898
024Perl 6190117T014214ZJo King
040PowerShell190116T162837ZAdmBorkB
048Common Lisp190117T121907Zcoredump
043Scala190116T165109ZXavier G
031Python 2190116T183101ZKirill L
038Julia 1.0190117T102600Ztrolley8
012Japt190116T165238ZShaggy
033C gcc190117T054916Zatt
022Wolfram Language Mathematica190116T164940Zalephalp
051Perl 5190116T194521ZBee H.
082Retina 0.8.2190117T004154ZNeil
030Java JDK190116T214039ZOlivier
4034R190116T184117Zngm
009Dyalog APL190116T163929Zdzaima
033C# .NET Core190116T163202ZDestroig
018Charcoal190116T183025ZNeil
01005AB1E190116T182324ZMagic Oc
081Batch190116T181404ZNeil
038Python 2190116T160928Zfəˈnɛtɪk
01205AB1E190116T170222ZCowabung
013Japt190116T163237ZOliver
011J190116T165311ZConor O&
034C gcc190116T163720Zcleblanc
030Python 2190116T164533ZArBo
028JavaScript ES6190116T160721ZArnauld

Raku (Perl 6) (rakudo), 35 bytes

->\x,\y{x==y||x+y==5||abs(x -y)==5}

Attempt This Online!

35 bytes, 34 chars

->\x,\y{x==y||x+y==5||(x -y)²==25}

Attempt This Online!

Tcl, 39 bytes

proc P a\ b {expr ($a-$b)%5<1|$a+$b==5}

Try it online!


# [Tcl], 40 bytes
proc P a\ b {expr ($a-$b)%5==0|$a+$b==5}

Try it online!


# [Tcl], 45 bytes
proc P a\ b {expr abs($a-$b)in{0 5}|$a+$b==5}

Try it online!

Bespoke, 230 bytes

input A,input B
do when both are of equal integral value
or=five,when we subtract/add all of it using absolute value
somewhat intricate math got us the quantity zero when doing products
after flipping(producing Booleans)I return N

Uses the same formula as DesmosEnthusiast's Desmos answer.

Outputs 1 for true and 0 for false. (I could remove 11 bytes and have it output 0 for true and anything nonzero for false, but I want to be safe!)

AWK, 34 bytes

$0=$1==$2||($1-$2)^2==25||$1+$2==5

Attempt This Online!

Couldn't get the previous AWK entry to work, so here we are.

Janet, 49 bytes

|(some|(=(-;$)5)[[$(- $1)][$ $1][$1 $][$ $1 -5]])

SAKO, 92 bytes

CZYTAJ:N,M
N=N-M
*)GDYABS(N)=5:2,INACZEJ1
1)N=N+M
POWTORZ:I=0(1)2
LINIA
2)LINIA
STOP2
KONIEC

Returns two LFs for False and one LF for True.

APL(NARS), 19 chars

{(0 5∊⍨∣⍺-⍵)∨5=⍵+⍺}

test:

  h←{(0 5∊⍨∣⍺-⍵)∨5=⍵+⍺}
  4 h 1
1
  10 h 10
1
  1 h 3
0
  6 h 2
0
  ¯256 h ¯251
1
  6 h 1
1
  ¯5 h 5
0
  ¯2 h ¯3
0

awk

30 bytes for the core expression

function ___(_,__){return(_+__!=5)<=(25==(_-=__)*_)^!!_}

4     1     =>  True   1
10    10    =>  True   1
1     3     =>  False  0
6     2     =>  False  0

1     6     =>  True   1
-256  -251  =>  True   1
6     1     =>  True   1
-5    5     =>  False  0

A fully POSIX-compliant awk solution that is also branch-free, bitwise-operator free, external function call free, recursion free, regex-free, and short-circuiting operator(s)-free.

^ := exponentiation in awk

Desmos, 28 bytes

f(a,b)=(a+b-5)(cc-25)c
c=b-a

f(a,b) returns 0 as a truthy value, any anything else as falsey. It works by setting the roots of a 3rd degree polynomial to -5,5, and 0, plugging in b-a for x, making it return 0 when b-a = -5,5, or 0. That other term, (a+b-5) is 0 when a+b = 5. This has the effect that when a+b = 5, the entire equation evaluates to 0.

Try it on Desmos!

Vyxal, 8 bytes

₍+ε5c□≈∨

Try it Online!

*><>, 33 bytes

:{:}=?;:{:}+5=?;-:0(?!u01-*O5=?;.

Try it online!

Could be lower if handling negative numbers wasn't a requirement. Uses the exit code as its truthy/falsey.

Initializes the stack with the -i flag, but this method can't handle negatives. The above code still works, but you must prepend your starting values to the start of the script. For example, the following works with the stack of [-15, 12]

53*0-c:{:}=?;:{:}+5=?;-:0(?!u01-*O5=?;.

Explanation

:{:}                                Duplicate the two values on the stack
    =?;                             If they're equal, halt execution
       :{:}                         Duplicate the two values on the stack, again
           +                        Add them together
            5=                      Check if that value is equal to 5
              ?;                    If so, halt execution
                -:                  Else, subtract our two values, and duplicate the result
                  0(                Check if the difference is less than 0
                    ?!u             If it is greater than 0, Dive and ignore instructions until we reach a Rise
                       01-*         If it isn't, multiply it by -1
                            O       Rise from our previous Dive. Ignored if there was no Dive.
                             5=     Check if our difference is equal to 5
                               ?;   If so, halt execution
                                 .  Else, throw an error

Factor, 37 bytes

[ 2dup + 5 = -rot - abs "\0"in? or ]

Try it online!

Explanation

"\0" Has literal 0 and 5 embedded in the string (you can see it on TIO). So "\0"in? is equivalent to { 0 5 } member? In other words, checking whether the input is 0 or 5.

          ! -256 -251
2dup      ! -256 -251 -256 -251
+         ! -256 -251 -507
5         ! -256 -251 -507 5
=         ! -256 -251 f
-rot      ! f -256 -251
-         ! f -5
abs       ! f 5
"\0"in?   ! f t
or        ! t

x86 machine code, 39 bytes

00000000: 6a01 5e6a 055f 5251 31c0 39d1 0f44 c601  j.^j._RQ1.9..D..
00000010: d139 cf0f 44c6 595a 29d1 83f9 050f 44c6  .9..D.YZ).....D.
00000020: 83f9 fb0f 44c6 c3                        ....D..

Assembly

section .text
	global func
func:					;inputs int32_t ecx and edx
	push 0x1
	pop esi
	push 0x5
	pop edi
	push edx
	push ecx
	xor eax, eax

	;ecx==edx?
	cmp ecx, edx
	cmove eax, esi

	;ecx+edx==5?
	add ecx, edx
	cmp edi, ecx
	cmove eax, esi
	
	;ecx-edx==5?
	pop ecx
	pop edx
	sub ecx, edx
	cmp ecx, 5
	
	;ecx-edx==-5?
	cmove eax, esi
	cmp ecx, -5
	cmove eax, esi

	ret

Try it online!

Edit: fixed bash stderr errors on TIO

Edit 2: improved formatting in TIO header and footer code

Factor, 44 40 bytes

Saved 4 bytes thanks to @chunes!

[ { [ = ] [ - abs 5 = ] [ + 5 = ] } || ]

Try it online!

The repetition of = is annoying, but I couldn't find another way.

|| tries out each of the three quotations in {...} and checks if the result is true for any of them. The first, [ = ], checks if they're equal, the second finds the absolute value of their difference and compares that to 5, and the third compares their sum to 5.

Pyth, 15 bytes

|!!/,a.*QsQ5q.*

Try it online!

Not super impressed, especially having to use double negation !! to cast a number into true... I'm sure there's a better way.

|!!/,a.*QsQ5q.*
   /,      5     Count '5's in: 
     a.*Q        Absolute value of (A, B)
         sQ      Sum of (A, B)
 !!              Cast to truthy
|                OR:
            q.*  A==B

Vyxal, 11 10 bytes

=£₌+ĸW5c¥∨

Try it Online!

Credits

x86-16 machine code, 21 20 bytes

00000000: 8bd0 2bc3 740d 7902 f7d8 3c05 7405 03d3  ..+.t.y...<.t...
00000010: 80fa 05c3                                ....

Listing:

8B D0       MOV  DX, AX     ; Save AX to DX 
2B C3       SUB  AX, BX     ; AX = AX - BX 
74 0D       JZ   DONE       ; if 0, they are equal (ZF=1) 
79 02       JNS  IS_POS     ; if positive, check if result is 5
F7 D8       NEG  AX         ; is negative, negate the result to get abs value
        IS_POS: 
3C 05       CMP  AL, 5      ; is result 5?
74 05       JZ   DONE       ; if so, exit with ZF=1
03 D3       ADD  DX, BX     ; DX = DX + BX
80 FA 05    CMP  DL, 5      ; ZF = ( DX == 5 )
        DONE:
C3          RET             ; return to caller

Input numbers in AX and BX and returns Zero Flag (ZF) if result is truthy.

Try it online! (testing code borrowed and adapted from @Logem's answer - thanks!)

Explanation:

If the difference between the numbers is 0, they are equal. Otherwise if result is negative, first negate it (abs value) and check for 5. If still not true, add and check for 5.

Bonus:

If desired, you can also determine which condition was true with the following:

Pyth, 12 bytes

}5[sQaFQ+4l{

Try it online!

}5[sQaFQ+4l{
}5[sQaFQ+4l{Q) // Implicit input and closed brace
  [          ) // Create an array of the following:
   sQ          //   Sum of input
     aFQ       //   Absolute difference of input
        +4l{Q  //   Length of unique values in input, + 4
}5             // Is '5' in the array? 

Desmos, 90 bytes

A pretty straightfoward solution, could definitely by golfed further:

f(a,b)=\left\{a+b=5:0,1\right\}\left\{\left|a-b\right|=5:0,1\right\}\left\{a=b:0,1\right\}

Try It On Desmos!

0 is true, and 1 is false.

Haskell, 30 Bytes

a?b=elem 5[a-b+5,abs(a-b),a+b]

Jelly, 7 bytes

+,ạ5eo=

Try it online!

How it works

+,ạ5eo=  Main link. Arguments: x, y (integers)

+        Yield x+y.
  ạ      Yield |x-y|.
 ,       Pair; yield (x+y, |x-y|).
   5e    Test if 5 exists in the pair.
      =  Test x and y for equality.
     o   Logical OR.

Brachylog, 8 bytes

=|+5|-ȧ5

Takes input as a list of two numbers (use _ for negatives). Try it online!

Explanation

Pretty much a direct translation of the spec:

=          The two numbers are equal
 |         or
  +        The sum of the two numbers
   5       is 5
    |      or
     -     The difference of the two numbers
      ȧ    absolute value
       5   is 5

Runic Enchantments, 27 bytes

i::i::}3s=?!@-'|A5:}=?!@+=@

Try it online!

Outputs 0 (exactly one zero) for false and any other output (literally whatever is left on the stack) for true.

New interpreter build, updated answer, saved 3 bytes (previous revision miscounted and said 4).

Explanation:

i::i::                         Read two inputs, duplicating each twice.
      }                        Rotate stack right
       3s                      Rotate the top 3 items to the right
         =? @                  Compare equal, if so, dump stack
           !                   If not, skip next instruction
             -'|A              Subtract, absolute value, (j)
                 5:}           Push two 5s, rotate one to the bottom
                    =? @       Compare 5 with (j), if equal, dump stack
                      ! +=     If not, add the two inputs, compare with remaining 5
                          @    Dump stack (will be 1 for true and 0 for false)

Essentially it reads both inputs 3 times and arranges the stack so that each operation works on a copy of each input (or a literal 5). As the only way to dump a 0 is if all three comparisons are false, simply dumping the rest of the stack avoids having to do anything other than vomiting the entire stack to output and terminating, all posibilities of which are valid truthy values.

Pascal (FPC), 26 70 bytes

Edit: + input variables.

Procedure z(a,b:integer);begin Writeln((abs(a-b)in[0,5])or(a+b=5))end;

Try it online!


(abs(a-b)in[0,5])or(a+b=5)

Try it online!

I hope that my answer is according to all rules of code-golf. It was fun anyway.

Ruby (>=1.9), 23 38 bytes

->(a,b){a==b or a+b==5 or(a-b).abs==5}

Try it online!

It's an anonymous function, so the TIO has some extra code to take input and return the output. Put the two numbers on separate lines.

Returns true if they are equal or add to 5, or if their absolute difference is 5, and false if not.

Ruby, 34 Bytes

->(a,b){[a+5,a-5,5-a,a].include?b}

Online Eval - Thanks @ASCII-Only

APL(NARS) 19 chars, 38 bytes

{∨/(⍺=⍵),5∊∣⍺+⍵,-⍵}

  f←{∨/(⍺=⍵),5∊∣⍺+⍵,-⍵}
  4 f 1
1
  1 f 3
0
  6 f 2
0
  1 f 6
1
  ¯256 f ¯251
1
  6 f 1
1
  ¯5 f 5
0

Perl 6, 24 bytes

-1 byte thanks to Grimy

{$^a-$^b==5|0|-5|5-2*$b}

Try it online!

This uses the Any Junction but technically, ^ could work as well.

Explanation:

{                      }  # Anonymous code block
 $^a-$^b==                # Is the difference equal to
           | |  |        # Any of
          0 
            5
              -5
                 5-2*$b

PowerShell, 48 44 40 bytes

param($a,$b)$b-in($a-5),(5-$a),(5+$a),$a

Try it online! or Verify all Test Cases

Takes input $a and $b. Checks if $b is -in the group ($a-5, 5-$a 5+$a, or $a), which checks all possible combinations of $a,$b, and 5.

-4 bytes thanks to mazzy.
-4 bytes thanks to KGlasier.

Common Lisp, 48 bytes

(lambda(a b)(find 5(list(abs(- b a))a(+ a b)b)))

Scala, 43 bytes

def f(a:Int,b:Int)=a+b==5|(a-b).abs==5|a==b

Try it online!

Python 2, 29 31 bytes

lambda a,b:a+b==5or`a-b`in"0-5"

Try it online!

Since I didn't manage to read the task carefully the first time, in order to fix it, I had to come up with a completely different approach, which is unfortunately not as concise.

Julia 1.0, 38 bytes

f(a,b)=((a+b-5)*(a-b)*(abs(a-b)-5))==0

Try it online!

Of course, it's probably not the shortest one

Japt, 13 12 bytes

x ¥5|50ìøUra

Try it or run all test cases

x ¥5|50ìøUra
                 :Implicit input of array U
x                :Reduce by addition
  ¥5             :Equal to 5?
    |            :Bitwise OR
     50ì         :Split 50 to an array of digits
        ø        :Contains?
         Ur      :  Reduce U
           a     :    By absolute difference

C (gcc), 33 bytes

f(a,b){a=!(a+b-5&&(a-=b)/6|a%5);}

Try it online!

Tried an approach I didn't see anyone else try using. The return expression is equivalent to a+b==5||((-6<a-b||a-b<6)&&(a-b)%5==0).


Wolfram Language (Mathematica), 22 bytes

Takes input as [a][b].

MatchQ[#|5-#|#-5|#+5]&

Try it online!

Perl 5, 51 bytes

Pretty simple really, uses the an flags for input. Outputs 0 for false, 1 for true. Not gonna lie, I don't know if bitwise OR is appropriate here, but is does work for all the test cases, so that's nice.

($a,$b)=@F;print($a==$b|$a+$b==5|$a-$b==5|$b-$a==5)

Try it online!

Retina 0.8.2, 82 bytes

\d+
$*
^(-?1*) \1$|^(-?1*)1{5} -?\2$|^-?(-?1*) (\3)1{5}$|^-?(1 ?){5}$|^(1 ?-?){5}$

Try it online! Link includes test cases. Explanation: The first two lines convert the inputs into unary. The final line then checks for any of the permitted matches:

^(-?1*) \1$                              x==y
^(-?1*)1{5} -?\2$   x>=0 y>=0 x=5+y i.e. x-y=5
                    x>=0 y<=0 x=5-y i.e. x+y=5
                    x<=0 y<=0 x=y-5 i.e. y-x=5
^-?(-?1*) (\3)1{5}$ x<=0 y<=0 y=x-5 i.e. x-y=5
                    x<=0 y>=0 y=5-x i.e. x+y=5
                    x>=0 y>=0 y=5+x i.e. y-x=5
^-?(1 ?){5}$        x>=0 y>=0 y=5-x i.e. x+y=5
                    x<=0 y>=0 y=5+x i.e. y-x=5
^(1 ?-?){5}$        x>=0 y>=0 x=5-y i.e. x+y=5
                    x>=0 y<=0 x=5+y i.e. x-y=5

Pivoted by the last column we get:

x==y            ^(-?1*) \1$
x+y=5 x>=0 y>=0 ^-?(1 ?){5}$
      x>=0 y>=0 ^(1 ?-?){5}$
      x>=0 y<=0 ^(-?1*)1{5} -?\2$
      x<=0 y>=0 ^-?(-?1*) (\3)1{5}$
      x<=0 y<=0 (impossible)       
x-y=5 x>=0 y>=0 ^(-?1*)1{5} -?\2$
      x>=0 y<=0 ^(1 ?-?){5}$
      x<=0 y>=0 (impossible)
      x<=0 y<=0 ^-?(-?1*) (\3)1{5}$
y-x=5 x>=0 y>=0 ^-?(-?1*) (\3)1{5}$
      x>=0 y<=0 (impossible)
      x<=0 y>=0 ^-?(1 ?){5}$
      x<=0 y<=0 ^(-?1*)1{5} -?\2$

Java (JDK), 30 bytes

a->b->a+b==5|a==b|(b-=a)*b==25

Try it online!

R, 40 bytes (or 34)

function(x,y)any((-1:1*5)%in%c(x+y,x-y))

Try it online!

For non-R users:

A direct port of @ArBo's solution has 35 34 bytes, so go upvote that answer if you like it:

function(x,y)x%in%c(y--1:1*5,5-y)

Dyalog APL, 9 bytes

=∨5∊+,∘|-

Try it online!

Spelled out:

  =   ∨  5      ∊                +   , ∘    |            -
equal or 5 found in an array of sum and absolute of difference.

C# (.NET Core), 43, 48, 47, 33 bytes

EDIT: Tried to use % and apparently forgot how to %. Thanks to Arnauld for pointing that out!

EDIT2: AdmBorkBork with a -1 byte golf rearranging the parentheses to sit next to the return so no additional space is needed!

EDIT3: Thanks to dana for -14 byte golf for the one-line return shortcut and currying the function (Ty Embodiment of Ignorance for linking to TIO).

C# (.NET Core), 33 bytes

a=>b=>a==b|a+b==5|(a-b)*(a-b)==25

Try it online!

Charcoal, 18 bytes

Nθ¿№⟦θ⁺⁵θ⁻⁵θ⁻θ⁵⟧N1

Try it online! Link is to verbose version of code. Port of @ArBo's Python 2 solution.

05AB1E, 10 bytes

OIÆ‚Ä50SåZ

Try it online!


O           # Sum the input.
 IÆ         # Reduced subtraction of the input.
   ‚        # Wrap [sum,reduced_subtraction]
    Ä       # abs[sum,red_sub]
     50S    # [5,0]
        å   # [5,0] in abs[sum,red_sub]?
         Z  # Max of result, 0 is false, 1 is true.

Tried to do it using stack-only operations, but it was longer.

Batch, 81 bytes

@set/as=%1+%2,d=%1-%2
@if %d% neq 0 if %d:-=% neq 5 if %s% neq 5 exit/b
@echo 1

Takes input as command-line arguments and outputs 1 on success, nothing on failure. Batch can't easily do disjunctions so I use De Morgan's laws to turn it into a conjunction.

Python 2, 38 bytes

-2 bytes thanks to @DjMcMayhem

lambda a,b:a+b==5or abs(a-b)==5or a==b

Try it online!

05AB1E, 13 12 bytes

ÐO5Qs`α5QrËO

Try it online!

Takes input as a list of integers, saving one byte. Thanks @Wisław!

Alternate 12 byte answer

Q¹²α5Q¹²+5QO

Try it online!

This one takes input on separate lines.

Japt, 14 13 bytes

¥VªaU ¥5ª5¥Nx

Try it online!

J, 12 11 bytes

1 byte saved thanks to Adám

1#.=+5=|@-,+

Try it online!

Explanation

This is equivalent to:

1 #. = + 5 = |@- , +

This can be divided into the following fork chain:

(= + (5 e. (|@- , +)))

Or, visualized using 5!:4<'f':

  ┌─ =               
  ├─ +               
──┤   ┌─ 5           
  │   ├─ e.          
  └───┤          ┌─ |
      │    ┌─ @ ─┴─ -
      └────┼─ ,      
           └─ +      

Annotated:

  ┌─ =                                     equality
  ├─ +                                     added to (boolean or)
──┤   ┌─ 5                                   noun 5
  │   ├─ e.                                  is an element of
  └───┤          ┌─ |  absolute value         |
      │    ┌─ @ ─┴─ -  (of) subtraction       |
      └────┼─ ,        paired with            |
           └─ +        addition               | any of these?

C (gcc), 41 34 bytes

f(a,b){a=5==abs(a-b)|a+b==5|a==b;}

Try it online!

Python 2, 30 bytes

lambda a,b:a in(b,5-b,b-5,b+5)

Try it online!

One byte saved by Arnauld

Three bytes saved by alephalpha

JavaScript (ES6), 28 bytes

Takes input as (a)(b). Returns \$0\$ or \$1\$.

a=>b=>a+b==5|!(a-=b)|a*a==25

Try it online!