| Bytes | Lang | Time | Link |
|---|---|---|---|
| 035 | Raku Perl 6 rakudo | 250321T160331Z | xrs |
| 039 | Tcl | 190116T164923Z | sergiol |
| 230 | Bespoke | 250410T103853Z | Josiah W |
| 034 | AWK | 250227T190829Z | xrs |
| 049 | Janet | 250320T111010Z | xigoi |
| 092 | SAKO | 250319T081445Z | Acrimori |
| 019 | APLNARS | 250228T135404Z | Rosario |
| nan | 250222T021638Z | RARE Kpo | |
| 028 | Desmos | 250222T010419Z | DesmosEn |
| 008 | Vyxal | 220705T195620Z | naffetS |
| 033 | *><> | 220705T193028Z | Bee H. |
| 037 | Factor | 220309T005529Z | chunes |
| 039 | x86 machine code | 190116T191551Z | user3604 |
| 040 | Factor | 210218T163530Z | user |
| 015 | Pyth | 210302T032447Z | Scott |
| 010 | Vyxal | 210301T130021Z | user1009 |
| 2120 | x8616 machine code | 190117T044505Z | 640KB |
| 012 | Pyth | 201123T022917Z | Scott |
| 090 | Desmos | 201121T211820Z | Aiden Ch |
| 030 | Haskell | 201014T212519Z | Benji |
| 007 | Jelly | 190116T162252Z | Dennis |
| 008 | Brachylog | 190216T042218Z | DLosc |
| 027 | Runic Enchantments | 190116T193537Z | Draco18s |
| 2670 | Pascal FPC | 190120T172459Z | Dessy St |
| 038 | Ruby >=1.9 | 190128T041623Z | CG One H |
| 034 | Ruby | 190120T115252Z | Jatin Dh |
| 038 | APLNARS 19 chars | 190123T100824Z | user5898 |
| 024 | Perl 6 | 190117T014214Z | Jo King |
| 040 | PowerShell | 190116T162837Z | AdmBorkB |
| 048 | Common Lisp | 190117T121907Z | coredump |
| 043 | Scala | 190116T165109Z | Xavier G |
| 031 | Python 2 | 190116T183101Z | Kirill L |
| 038 | Julia 1.0 | 190117T102600Z | trolley8 |
| 012 | Japt | 190116T165238Z | Shaggy |
| 033 | C gcc | 190117T054916Z | att |
| 022 | Wolfram Language Mathematica | 190116T164940Z | alephalp |
| 051 | Perl 5 | 190116T194521Z | Bee H. |
| 082 | Retina 0.8.2 | 190117T004154Z | Neil |
| 030 | Java JDK | 190116T214039Z | Olivier |
| 4034 | R | 190116T184117Z | ngm |
| 009 | Dyalog APL | 190116T163929Z | dzaima |
| 033 | C# .NET Core | 190116T163202Z | Destroig |
| 018 | Charcoal | 190116T183025Z | Neil |
| 010 | 05AB1E | 190116T182324Z | Magic Oc |
| 081 | Batch | 190116T181404Z | Neil |
| 038 | Python 2 | 190116T160928Z | fəˈnɛtɪk |
| 012 | 05AB1E | 190116T170222Z | Cowabung |
| 013 | Japt | 190116T163237Z | Oliver |
| 011 | J | 190116T165311Z | Conor O& |
| 034 | C gcc | 190116T163720Z | cleblanc |
| 030 | Python 2 | 190116T164533Z | ArBo |
| 028 | JavaScript ES6 | 190116T160721Z | Arnauld |
Raku (Perl 6) (rakudo), 35 bytes
->\x,\y{x==y||x+y==5||abs(x -y)==5}
35 bytes, 34 chars
->\x,\y{x==y||x+y==5||(x -y)²==25}
Tcl, 39 bytes
proc P a\ b {expr ($a-$b)%5<1|$a+$b==5}
proc P a\ b {expr ($a-$b)%5==0|$a+$b==5}
proc P a\ b {expr abs($a-$b)in{0 5}|$a+$b==5}
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
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 inawk
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.
*><>, 33 bytes
:{:}=?;:{:}+5=?;-:0(?!u01-*O5=?;.
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 ]
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
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 = ] } || ]
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.*
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¥∨
Credits
- Saved 1 byte thanks to @Lyxal by employing the use of an absolute difference built-in
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:
ZF=1andDX=5; sum is 5ZF=1andAX=5; diff is 5ZF=1andAX=0; equalZF=0; falsey
Pyth, 12 bytes
}5[sQaFQ+4l{
}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\}
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=
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:}=?!@+=@
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;
(abs(a-b)in[0,5])or(a+b=5)
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}
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.
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}
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)))
Python 2, 29 31 bytes
lambda a,b:a+b==5or`a-b`in"0-5"
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
Of course, it's probably not the shortest one
Japt, 13 12 bytes
x ¥5|50ìøUra
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);}
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).
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)
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$
R, 40 bytes (or 34)
function(x,y)any((-1:1*5)%in%c(x+y,x-y))
For non-R users:
-1:1*5expands to[-5, 0, 5]- the
%in%operator takes elements from the left and checks (element-wise) if they exist in the vector on the right
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∊+,∘|-
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
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
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
05AB1E, 13 12 bytes
ÐO5Qs`α5QrËO
Takes input as a list of integers, saving one byte. Thanks @Wisław!
Alternate 12 byte answer
Q¹²α5Q¹²+5QO
This one takes input on separate lines.
J, 12 11 bytes
1 byte saved thanks to Adám
1#.=+5=|@-,+
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?
Python 2, 30 bytes
lambda a,b:a in(b,5-b,b-5,b+5)
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
