Equal, sum or difference!
$begingroup$
Write shortest possible code that will return true if the two given integer values are equal or their sum or absolute difference is 5.
Example test cases:
4 1 => True
10 10 => True
1 3 => False
6 2 => False
1 6 => True
-256 -251 => True
6 1 => True
-5 5 => False
The shortest I could come up with in python2 is 56 characters long:
x=input();y=input();print all([x-y,x+y-5,abs(x-y)-5])<1
-9, thanks @ElPedro. It takes input in format x,y:
x,y=input();print all([x-y,x+y-5,abs(x-y)-5])<1
code-golf decision-problem
$endgroup$
add a comment |
$begingroup$
Write shortest possible code that will return true if the two given integer values are equal or their sum or absolute difference is 5.
Example test cases:
4 1 => True
10 10 => True
1 3 => False
6 2 => False
1 6 => True
-256 -251 => True
6 1 => True
-5 5 => False
The shortest I could come up with in python2 is 56 characters long:
x=input();y=input();print all([x-y,x+y-5,abs(x-y)-5])<1
-9, thanks @ElPedro. It takes input in format x,y:
x,y=input();print all([x-y,x+y-5,abs(x-y)-5])<1
code-golf decision-problem
$endgroup$
9
$begingroup$
welcome to PPCG! This is a good first challenge -- the challenge is clearly defined, it has ample test cases, and uses our default I/O! If you stick around for a while and keep thinking up interesting challenges, I would recommend using The Sandbox to get feedback before posting them to this site. I hope you enjoy the time you spend here!
$endgroup$
– Giuseppe
Jan 16 at 16:22
add a comment |
$begingroup$
Write shortest possible code that will return true if the two given integer values are equal or their sum or absolute difference is 5.
Example test cases:
4 1 => True
10 10 => True
1 3 => False
6 2 => False
1 6 => True
-256 -251 => True
6 1 => True
-5 5 => False
The shortest I could come up with in python2 is 56 characters long:
x=input();y=input();print all([x-y,x+y-5,abs(x-y)-5])<1
-9, thanks @ElPedro. It takes input in format x,y:
x,y=input();print all([x-y,x+y-5,abs(x-y)-5])<1
code-golf decision-problem
$endgroup$
Write shortest possible code that will return true if the two given integer values are equal or their sum or absolute difference is 5.
Example test cases:
4 1 => True
10 10 => True
1 3 => False
6 2 => False
1 6 => True
-256 -251 => True
6 1 => True
-5 5 => False
The shortest I could come up with in python2 is 56 characters long:
x=input();y=input();print all([x-y,x+y-5,abs(x-y)-5])<1
-9, thanks @ElPedro. It takes input in format x,y:
x,y=input();print all([x-y,x+y-5,abs(x-y)-5])<1
code-golf decision-problem
code-golf decision-problem
edited Jan 17 at 9:45
Vikrant Biswas
asked Jan 16 at 15:58
Vikrant BiswasVikrant Biswas
16426
16426
9
$begingroup$
welcome to PPCG! This is a good first challenge -- the challenge is clearly defined, it has ample test cases, and uses our default I/O! If you stick around for a while and keep thinking up interesting challenges, I would recommend using The Sandbox to get feedback before posting them to this site. I hope you enjoy the time you spend here!
$endgroup$
– Giuseppe
Jan 16 at 16:22
add a comment |
9
$begingroup$
welcome to PPCG! This is a good first challenge -- the challenge is clearly defined, it has ample test cases, and uses our default I/O! If you stick around for a while and keep thinking up interesting challenges, I would recommend using The Sandbox to get feedback before posting them to this site. I hope you enjoy the time you spend here!
$endgroup$
– Giuseppe
Jan 16 at 16:22
9
9
$begingroup$
welcome to PPCG! This is a good first challenge -- the challenge is clearly defined, it has ample test cases, and uses our default I/O! If you stick around for a while and keep thinking up interesting challenges, I would recommend using The Sandbox to get feedback before posting them to this site. I hope you enjoy the time you spend here!
$endgroup$
– Giuseppe
Jan 16 at 16:22
$begingroup$
welcome to PPCG! This is a good first challenge -- the challenge is clearly defined, it has ample test cases, and uses our default I/O! If you stick around for a while and keep thinking up interesting challenges, I would recommend using The Sandbox to get feedback before posting them to this site. I hope you enjoy the time you spend here!
$endgroup$
– Giuseppe
Jan 16 at 16:22
add a comment |
35 Answers
35
active
oldest
votes
1 2
next
$begingroup$
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
$endgroup$
$begingroup$
This is amazingly concise, thanks
$endgroup$
– Vikrant Biswas
Jan 16 at 17:17
$begingroup$
Same can be done in Octave/MATLAB in 29 bytes (Try it online!).
$endgroup$
– Tom Carpenter
Jan 17 at 18:51
add a comment |
$begingroup$
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!
$endgroup$
1
$begingroup$
Damn, took me a long long time to figure out how this handling the difference part. :)
$endgroup$
– Vikrant Biswas
Jan 16 at 19:34
add a comment |
$begingroup$
Dyalog APL, 9 bytes
=∨5∊+,∘|-
Try it online!
Spelled out:
= ∨ 5 ∊ + , ∘ | -
equal or 5 found in an array of sum and absolute of difference.
$endgroup$
add a comment |
$begingroup$
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!
$endgroup$
add a comment |
$begingroup$
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?
$endgroup$
$begingroup$
Save a byte withe.
$endgroup$
– Adám
Jan 16 at 16:58
$begingroup$
@Adám How so? Shortest approach I got withe.
was=+.5 e.|@-,+
. Maybe you forget5e.
is an invalid token in J?
$endgroup$
– Conor O'Brien
Jan 16 at 17:05
1
$begingroup$
Since two integers cannot simultaneously sum to 5 and be equal, you can use+
instead of+.
$endgroup$
– Adám
Jan 16 at 17:11
$begingroup$
@Adám Ah, I see, thank you.
$endgroup$
– Conor O'Brien
Jan 16 at 17:15
add a comment |
$begingroup$
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:
-1:1*5
expands 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)
$endgroup$
$begingroup$
The 34 byte one can be reduced by 1 withfunction(x,y)x%in%c(y--1:1*5,5-y)
$endgroup$
– MickyT
Jan 16 at 21:36
$begingroup$
Can drop to 30 bytes by moving the subtraction:function(x,y)(x-y)%in%(-1:1*5)
, and drop it further to 24 bytes by dropping the function notation toscan()
input:diff(scan())%in%(-1:1*5)
Try it online!. Still very much the same method though.
$endgroup$
– CriminallyVulgar
Jan 17 at 14:38
1
$begingroup$
@CriminallyVulgar does that account for the sum being 5?
$endgroup$
– ArBo
Jan 17 at 15:45
$begingroup$
@ArBo Hah, missed that in the spec, and there wasn't a test case in the TIO so I just glossed over it!
$endgroup$
– CriminallyVulgar
Jan 18 at 9:39
$begingroup$
Minor change that can be made to both is to usepryr::f
, which happens to work in both cases. Whether it can properly detect the arguments is entirely somewhat hit or miss but it seems to nail these two functions. e.g.pryr::f(x%in%c(y--1:1*5,5-y))
Try it online!. Gets you to 36 and 29 bytes respectively.
$endgroup$
– CriminallyVulgar
Jan 18 at 15:50
add a comment |
$begingroup$
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.
$endgroup$
add a comment |
$begingroup$
8086 machine code, 22 20 bytes
8bd0 2bc3 740e 7902 f7d8 3d0500 7405 03d3 83fa05
Ungolfed:
ESD MACRO
LOCAL SUB_POS, DONE
MOV DX, AX ; Save AX to DX
SUB AX, BX ; AX = AX - BX
JZ DONE ; if 0, then they are equal, ZF=1
JNS SUB_POS ; if positive, go to SUB_POS
NEG AX ; otherwise negate the result
SUB_POS:
CMP AX, 5 ; if result is 5, ZF=1
JZ DONE
ADD DX, BX ; DX = DX + BX
CMP DX, 5 ; if 5, ZF=1
DONE:
ENDM
Input numbers in AX and BX and returns Zero Flag (ZF=1) if result is true. If desired, you can also determine which condition was true with the following:
- ZF = 1 and DX = 5 ; sum is 5
- ZF = 1 and AX = 5 ; diff is 5
- ZF = 1 and AX = 0 ; equal
- ZF = 0 ; result false
If the difference between the numbers is 0, we know they are equal. Otherwise if result is negative, then first negate it and then check for 5. If still not true, then add and check for 5.
Sample PC DOS test program. Download it here (ESD.COM).
START:
CALL INDEC ; input first number into AX
MOV BX, AX ; move to BX
CALL INDEC ; input second number into BX
ESD ; run "Equal, sum or difference" routine
JZ TRUE ; if ZF=1, result is true
FALSE:
MOV DX, OFFSET FALSY ; load Falsy string
JMP DONE
TRUE:
MOV DX, OFFSET TRUTHY ; load Truthy string
DONE:
MOV AH, 9 ; DOS display string
INT 21H ; execute
MOV AX, 4C00H ; DOS terminate
INT 21H ; execute
TRUTHY DB 'Truthy$'
FALSY DB 'Falsy$'
INCLUDE INDEC.ASM ; generic decimal input prompt routine
Output of test program:
A>ESD.COM
: 4
: 1
Truthy
A>ESD.COM
: 10
: 10
Truthy
A>ESD.COM
: 1
: 3
Falsy
A>ESD.COM
: 6
: 2
Falsy
A>ESD.COM
: 1
: 6
Truthy
A>ESD.COM
: -256
: -251
Truthy
A>ESD.COM
: 6
: 1
Truthy
A>ESD.COM
: 9999999999
: 9999999994
Truthy
$endgroup$
add a comment |
$begingroup$
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 fi 5 exists in the pair.
= Test x and y for equality.
o Logical OR.
$endgroup$
add a comment |
$begingroup$
Python 2, 38 bytes
-2 bytes thanks to @DjMcMayhem
lambda a,b:a+b==5or abs(a-b)==5or a==b
Try it online!
$endgroup$
$begingroup$
Your TIO is actually 42 bytes but you can fix it by deleting the spaces between the5
s and theor
s
$endgroup$
– ElPedro
Jan 16 at 16:12
3
$begingroup$
Actually, the TIO link could be 38 bytes
$endgroup$
– DJMcMayhem♦
Jan 16 at 16:14
$begingroup$
@ElPedro the function itself was 40 bytes but I used f= in order to be able to call it
$endgroup$
– fəˈnɛtɪk
Jan 16 at 18:10
1
$begingroup$
@DJMcMayhem I don't normally golf in python. I just did it because the question asker used python for their example
$endgroup$
– fəˈnɛtɪk
Jan 16 at 18:12
add a comment |
$begingroup$
Java (JDK), 30 bytes
a->b->a+b==5|a==b|(b-=a)*b==25
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 22 bytes
Takes input as [a][b]
.
MatchQ[#|5-#|#-5|#+5]&
Try it online!
$endgroup$
add a comment |
$begingroup$
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.
$endgroup$
$begingroup$
($a-$b)
is-$x
:)
$endgroup$
– mazzy
Jan 16 at 17:14
$begingroup$
@mazzy Ooo, good call.
$endgroup$
– AdmBorkBork
Jan 16 at 17:41
$begingroup$
If you switch5
and$b
around you can cut off a couple bytes(ieparam($a,$b)$b-in($a-5),(5-$a),($a+5),$a
) Try it out here
$endgroup$
– KGlasier
Jan 17 at 15:13
1
$begingroup$
@KGlasier Excellent suggestion. I needed to swap$a+5
to5+$a
to get it to cast appropriately when taking command-line input, but otherwise awesome. Thanks!
$endgroup$
– AdmBorkBork
Jan 17 at 15:55
add a comment |
$begingroup$
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.
$endgroup$
2
$begingroup$
Hello, and welcome to PPCG! Normally, you have to take input, instead of assuming it is already in variables. I don't know Pascal, but I think that is what this code is doing.
$endgroup$
– NoOneIsHere
Jan 20 at 17:42
$begingroup$
Hello, NoOneIsHere and thank you for the remark. It was may concern too - shall I include the initialization of the variables. Looking at several other solutions, like Java for example, where the function definition with parameters was excluded from the total length of the solution, I decided not to include ReadLn.
$endgroup$
– Dessy Stoeva
Jan 20 at 18:42
$begingroup$
Alright. Welcome to PPCG!
$endgroup$
– NoOneIsHere
Jan 20 at 23:47
$begingroup$
The Java submission is an anonymous lambda which takes two parameters. This appears to use predefined variables, which is not a valid method of input.
$endgroup$
– Jo King
Jan 24 at 11:08
1
$begingroup$
No problem, I will change my submission.
$endgroup$
– Dessy Stoeva
Jan 24 at 13:55
add a comment |
$begingroup$
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!
$endgroup$
$begingroup$
Bah. Trying to avoid System.Math. Back to it! Thanks for pointing that out :D
$endgroup$
– Destroigo
Jan 16 at 16:41
1
$begingroup$
You can get it down to 33 bytes applying dana's tips
$endgroup$
– Embodiment of Ignorance
Jan 16 at 18:10
add a comment |
$begingroup$
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)
.
$endgroup$
add a comment |
$begingroup$
Scala, 43 bytes
def f(a:Int,b:Int)=a+b==5|(a-b).abs==5|a==b
Try it online!
$endgroup$
$begingroup$
Isn't it possible to golf the||
to|
? I know it's possible in Java, C#, Python, or JavaScript, but not sure about Scala.
$endgroup$
– Kevin Cruijssen
Jan 17 at 12:15
$begingroup$
Actually yes! thanks
$endgroup$
– Xavier Guihot
Jan 17 at 12:18
add a comment |
$begingroup$
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
$endgroup$
1
$begingroup$
-1 byte with{$^a-$^b==5|0|-5|5-2*$b}
$endgroup$
– Grimy
Jan 17 at 15:00
add a comment |
$begingroup$
C (gcc), 41 34 bytes
f(a,b){a=5==abs(a-b)|a+b==5|a==b;}
Try it online!
$endgroup$
1
$begingroup$
Why doesf
returna
? Just some Undefined Behavior?
$endgroup$
– Tyilo
Jan 16 at 17:05
$begingroup$
@Tyilo Yes, it's implementation specific. So happens the first parameter is stored in the same register as the return value.
$endgroup$
– cleblanc
Jan 16 at 17:07
$begingroup$
30 bytes Try it online!
$endgroup$
– Logern
Jan 16 at 18:02
$begingroup$
@Logern Doesn't work for f(6,1)
$endgroup$
– cleblanc
Jan 16 at 18:31
$begingroup$
@ceilingcat Doesn't work for f(6,1)
$endgroup$
– cleblanc
Jan 16 at 18:32
|
show 2 more comments
$begingroup$
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.
$endgroup$
1
$begingroup$
Since it is not very clearly specified, can you not assume the input is a list of integers, thus eliminating the initial|
?
$endgroup$
– Wisław
Jan 16 at 17:22
$begingroup$
@Wisław Good point, I updated my answer. Thanks!
$endgroup$
– Cowabunghole
Jan 16 at 17:28
$begingroup$
I found a 11 bytes alternative:OI`αª5¢IË~Ā
. Input is a list of integers.
$endgroup$
– Wisław
Jan 16 at 17:54
1
$begingroup$
OIÆÄ)5QIËM
is 10.
$endgroup$
– Magic Octopus Urn
Jan 16 at 18:35
1
$begingroup$
@MagicOctopusUrn I'm not sure exactly what the rules are but I think your solution is different enough from mine to submit your own answer, no? Also, unrelated but I've seen your username on this site for a long time but only after typing it out did I realize that it's "Urn", not "Um" :)
$endgroup$
– Cowabunghole
Jan 16 at 18:43
|
show 2 more comments
$begingroup$
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.
$endgroup$
1
$begingroup$
This will unfortunately return true if the sum is0
such as for[5, -5]
$endgroup$
– Emigna
Jan 16 at 20:28
1
$begingroup$
Your other 10-byte solution that you left as a comment (OIÆÄ‚5QIËM
) is correct for[5,-5]
.
$endgroup$
– Kevin Cruijssen
Jan 17 at 9:31
$begingroup$
Another 10-byte solution that I came up with isOsÆÄ‚5åsË~
. Almost identical to yours it seems. Try it online!
$endgroup$
– Wisław
Jan 17 at 10:54
add a comment |
$begingroup$
Ruby, 34 Bytes
->(a,b){[a+5,a-5,5-a,a].include?b}
Online Eval
- Thanks @ASCII-Only
$endgroup$
$begingroup$
do you check if they're equal though...
$endgroup$
– ASCII-only
Jan 20 at 12:20
$begingroup$
Oops, forgot to add that check. Thanks @ASCII-only for pointing out the mistake.
$endgroup$
– Jatin Dhankhar
Jan 20 at 12:23
1
$begingroup$
i'd be nice if you could link to this
$endgroup$
– ASCII-only
Jan 21 at 2:57
$begingroup$
this might be valid? not completely sure though, you might wanna check with someone else
$endgroup$
– ASCII-only
Jan 28 at 4:45
$begingroup$
This will work but it requires.nil?
check to give output in the required format.->(a,b){[a+5,a-5,5-a,a].index(b).nil?}
, this is longer than the current one.
$endgroup$
– Jatin Dhankhar
Jan 28 at 5:04
|
show 1 more comment
$begingroup$
Tcl, 53 bytes
proc P a b {expr abs($a-$b)==5|$a==$b|abs($a+$b)==5}
Try it online!
$endgroup$
add a comment |
$begingroup$
Japt, 14 13 bytes
¥VªaU ¥5ª5¥Nx
Try it online!
$endgroup$
add a comment |
$begingroup$
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.
$endgroup$
add a comment |
$begingroup$
Charcoal, 18 bytes
Nθ¿№⟦θ⁺⁵θ⁻⁵θ⁻θ⁵⟧N1
Try it online! Link is to verbose version of code. Port of @ArBo's Python 2 solution.
$endgroup$
add a comment |
$begingroup$
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
$endgroup$
$begingroup$
Fails for[-5,5]
(should be falsey)
$endgroup$
– Kevin Cruijssen
Jan 17 at 9:26
$begingroup$
Thanks, @KevinCruijssen. Rolled back to the previous version.
$endgroup$
– Shaggy
Jan 17 at 9:50
add a comment |
$begingroup$
Common Lisp, 48 bytes
(lambda(a b)(find 5(list(abs(- b a))a(+ a b)b)))
$endgroup$
add a comment |
$begingroup$
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
$endgroup$
add a comment |
$begingroup$
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$
$endgroup$
add a comment |
1 2
next
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "200"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f178792%2fequal-sum-or-difference%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
35 Answers
35
active
oldest
votes
35 Answers
35
active
oldest
votes
active
oldest
votes
active
oldest
votes
1 2
next
$begingroup$
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
$endgroup$
$begingroup$
This is amazingly concise, thanks
$endgroup$
– Vikrant Biswas
Jan 16 at 17:17
$begingroup$
Same can be done in Octave/MATLAB in 29 bytes (Try it online!).
$endgroup$
– Tom Carpenter
Jan 17 at 18:51
add a comment |
$begingroup$
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
$endgroup$
$begingroup$
This is amazingly concise, thanks
$endgroup$
– Vikrant Biswas
Jan 16 at 17:17
$begingroup$
Same can be done in Octave/MATLAB in 29 bytes (Try it online!).
$endgroup$
– Tom Carpenter
Jan 17 at 18:51
add a comment |
$begingroup$
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
$endgroup$
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
edited Jan 16 at 16:54
answered Jan 16 at 16:45
ArBoArBo
33115
33115
$begingroup$
This is amazingly concise, thanks
$endgroup$
– Vikrant Biswas
Jan 16 at 17:17
$begingroup$
Same can be done in Octave/MATLAB in 29 bytes (Try it online!).
$endgroup$
– Tom Carpenter
Jan 17 at 18:51
add a comment |
$begingroup$
This is amazingly concise, thanks
$endgroup$
– Vikrant Biswas
Jan 16 at 17:17
$begingroup$
Same can be done in Octave/MATLAB in 29 bytes (Try it online!).
$endgroup$
– Tom Carpenter
Jan 17 at 18:51
$begingroup$
This is amazingly concise, thanks
$endgroup$
– Vikrant Biswas
Jan 16 at 17:17
$begingroup$
This is amazingly concise, thanks
$endgroup$
– Vikrant Biswas
Jan 16 at 17:17
$begingroup$
Same can be done in Octave/MATLAB in 29 bytes (Try it online!).
$endgroup$
– Tom Carpenter
Jan 17 at 18:51
$begingroup$
Same can be done in Octave/MATLAB in 29 bytes (Try it online!).
$endgroup$
– Tom Carpenter
Jan 17 at 18:51
add a comment |
$begingroup$
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!
$endgroup$
1
$begingroup$
Damn, took me a long long time to figure out how this handling the difference part. :)
$endgroup$
– Vikrant Biswas
Jan 16 at 19:34
add a comment |
$begingroup$
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!
$endgroup$
1
$begingroup$
Damn, took me a long long time to figure out how this handling the difference part. :)
$endgroup$
– Vikrant Biswas
Jan 16 at 19:34
add a comment |
$begingroup$
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!
$endgroup$
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!
edited Jan 16 at 16:20
answered Jan 16 at 16:07


ArnauldArnauld
76.5k693321
76.5k693321
1
$begingroup$
Damn, took me a long long time to figure out how this handling the difference part. :)
$endgroup$
– Vikrant Biswas
Jan 16 at 19:34
add a comment |
1
$begingroup$
Damn, took me a long long time to figure out how this handling the difference part. :)
$endgroup$
– Vikrant Biswas
Jan 16 at 19:34
1
1
$begingroup$
Damn, took me a long long time to figure out how this handling the difference part. :)
$endgroup$
– Vikrant Biswas
Jan 16 at 19:34
$begingroup$
Damn, took me a long long time to figure out how this handling the difference part. :)
$endgroup$
– Vikrant Biswas
Jan 16 at 19:34
add a comment |
$begingroup$
Dyalog APL, 9 bytes
=∨5∊+,∘|-
Try it online!
Spelled out:
= ∨ 5 ∊ + , ∘ | -
equal or 5 found in an array of sum and absolute of difference.
$endgroup$
add a comment |
$begingroup$
Dyalog APL, 9 bytes
=∨5∊+,∘|-
Try it online!
Spelled out:
= ∨ 5 ∊ + , ∘ | -
equal or 5 found in an array of sum and absolute of difference.
$endgroup$
add a comment |
$begingroup$
Dyalog APL, 9 bytes
=∨5∊+,∘|-
Try it online!
Spelled out:
= ∨ 5 ∊ + , ∘ | -
equal or 5 found in an array of sum and absolute of difference.
$endgroup$
Dyalog APL, 9 bytes
=∨5∊+,∘|-
Try it online!
Spelled out:
= ∨ 5 ∊ + , ∘ | -
equal or 5 found in an array of sum and absolute of difference.
edited Jan 16 at 21:21
answered Jan 16 at 16:39


dzaimadzaima
15.2k21856
15.2k21856
add a comment |
add a comment |
$begingroup$
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!
$endgroup$
add a comment |
$begingroup$
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!
$endgroup$
add a comment |
$begingroup$
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!
$endgroup$
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!
answered Jan 16 at 19:15
LogernLogern
81556
81556
add a comment |
add a comment |
$begingroup$
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?
$endgroup$
$begingroup$
Save a byte withe.
$endgroup$
– Adám
Jan 16 at 16:58
$begingroup$
@Adám How so? Shortest approach I got withe.
was=+.5 e.|@-,+
. Maybe you forget5e.
is an invalid token in J?
$endgroup$
– Conor O'Brien
Jan 16 at 17:05
1
$begingroup$
Since two integers cannot simultaneously sum to 5 and be equal, you can use+
instead of+.
$endgroup$
– Adám
Jan 16 at 17:11
$begingroup$
@Adám Ah, I see, thank you.
$endgroup$
– Conor O'Brien
Jan 16 at 17:15
add a comment |
$begingroup$
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?
$endgroup$
$begingroup$
Save a byte withe.
$endgroup$
– Adám
Jan 16 at 16:58
$begingroup$
@Adám How so? Shortest approach I got withe.
was=+.5 e.|@-,+
. Maybe you forget5e.
is an invalid token in J?
$endgroup$
– Conor O'Brien
Jan 16 at 17:05
1
$begingroup$
Since two integers cannot simultaneously sum to 5 and be equal, you can use+
instead of+.
$endgroup$
– Adám
Jan 16 at 17:11
$begingroup$
@Adám Ah, I see, thank you.
$endgroup$
– Conor O'Brien
Jan 16 at 17:15
add a comment |
$begingroup$
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?
$endgroup$
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?
edited Jan 16 at 17:20
answered Jan 16 at 16:53


Conor O'BrienConor O'Brien
30.1k264162
30.1k264162
$begingroup$
Save a byte withe.
$endgroup$
– Adám
Jan 16 at 16:58
$begingroup$
@Adám How so? Shortest approach I got withe.
was=+.5 e.|@-,+
. Maybe you forget5e.
is an invalid token in J?
$endgroup$
– Conor O'Brien
Jan 16 at 17:05
1
$begingroup$
Since two integers cannot simultaneously sum to 5 and be equal, you can use+
instead of+.
$endgroup$
– Adám
Jan 16 at 17:11
$begingroup$
@Adám Ah, I see, thank you.
$endgroup$
– Conor O'Brien
Jan 16 at 17:15
add a comment |
$begingroup$
Save a byte withe.
$endgroup$
– Adám
Jan 16 at 16:58
$begingroup$
@Adám How so? Shortest approach I got withe.
was=+.5 e.|@-,+
. Maybe you forget5e.
is an invalid token in J?
$endgroup$
– Conor O'Brien
Jan 16 at 17:05
1
$begingroup$
Since two integers cannot simultaneously sum to 5 and be equal, you can use+
instead of+.
$endgroup$
– Adám
Jan 16 at 17:11
$begingroup$
@Adám Ah, I see, thank you.
$endgroup$
– Conor O'Brien
Jan 16 at 17:15
$begingroup$
Save a byte with
e.
$endgroup$
– Adám
Jan 16 at 16:58
$begingroup$
Save a byte with
e.
$endgroup$
– Adám
Jan 16 at 16:58
$begingroup$
@Adám How so? Shortest approach I got with
e.
was =+.5 e.|@-,+
. Maybe you forget 5e.
is an invalid token in J?$endgroup$
– Conor O'Brien
Jan 16 at 17:05
$begingroup$
@Adám How so? Shortest approach I got with
e.
was =+.5 e.|@-,+
. Maybe you forget 5e.
is an invalid token in J?$endgroup$
– Conor O'Brien
Jan 16 at 17:05
1
1
$begingroup$
Since two integers cannot simultaneously sum to 5 and be equal, you can use
+
instead of +.
$endgroup$
– Adám
Jan 16 at 17:11
$begingroup$
Since two integers cannot simultaneously sum to 5 and be equal, you can use
+
instead of +.
$endgroup$
– Adám
Jan 16 at 17:11
$begingroup$
@Adám Ah, I see, thank you.
$endgroup$
– Conor O'Brien
Jan 16 at 17:15
$begingroup$
@Adám Ah, I see, thank you.
$endgroup$
– Conor O'Brien
Jan 16 at 17:15
add a comment |
$begingroup$
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:
-1:1*5
expands 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)
$endgroup$
$begingroup$
The 34 byte one can be reduced by 1 withfunction(x,y)x%in%c(y--1:1*5,5-y)
$endgroup$
– MickyT
Jan 16 at 21:36
$begingroup$
Can drop to 30 bytes by moving the subtraction:function(x,y)(x-y)%in%(-1:1*5)
, and drop it further to 24 bytes by dropping the function notation toscan()
input:diff(scan())%in%(-1:1*5)
Try it online!. Still very much the same method though.
$endgroup$
– CriminallyVulgar
Jan 17 at 14:38
1
$begingroup$
@CriminallyVulgar does that account for the sum being 5?
$endgroup$
– ArBo
Jan 17 at 15:45
$begingroup$
@ArBo Hah, missed that in the spec, and there wasn't a test case in the TIO so I just glossed over it!
$endgroup$
– CriminallyVulgar
Jan 18 at 9:39
$begingroup$
Minor change that can be made to both is to usepryr::f
, which happens to work in both cases. Whether it can properly detect the arguments is entirely somewhat hit or miss but it seems to nail these two functions. e.g.pryr::f(x%in%c(y--1:1*5,5-y))
Try it online!. Gets you to 36 and 29 bytes respectively.
$endgroup$
– CriminallyVulgar
Jan 18 at 15:50
add a comment |
$begingroup$
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:
-1:1*5
expands 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)
$endgroup$
$begingroup$
The 34 byte one can be reduced by 1 withfunction(x,y)x%in%c(y--1:1*5,5-y)
$endgroup$
– MickyT
Jan 16 at 21:36
$begingroup$
Can drop to 30 bytes by moving the subtraction:function(x,y)(x-y)%in%(-1:1*5)
, and drop it further to 24 bytes by dropping the function notation toscan()
input:diff(scan())%in%(-1:1*5)
Try it online!. Still very much the same method though.
$endgroup$
– CriminallyVulgar
Jan 17 at 14:38
1
$begingroup$
@CriminallyVulgar does that account for the sum being 5?
$endgroup$
– ArBo
Jan 17 at 15:45
$begingroup$
@ArBo Hah, missed that in the spec, and there wasn't a test case in the TIO so I just glossed over it!
$endgroup$
– CriminallyVulgar
Jan 18 at 9:39
$begingroup$
Minor change that can be made to both is to usepryr::f
, which happens to work in both cases. Whether it can properly detect the arguments is entirely somewhat hit or miss but it seems to nail these two functions. e.g.pryr::f(x%in%c(y--1:1*5,5-y))
Try it online!. Gets you to 36 and 29 bytes respectively.
$endgroup$
– CriminallyVulgar
Jan 18 at 15:50
add a comment |
$begingroup$
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:
-1:1*5
expands 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)
$endgroup$
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:
-1:1*5
expands 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)
edited Jan 16 at 21:39
answered Jan 16 at 18:41
ngmngm
3,36924
3,36924
$begingroup$
The 34 byte one can be reduced by 1 withfunction(x,y)x%in%c(y--1:1*5,5-y)
$endgroup$
– MickyT
Jan 16 at 21:36
$begingroup$
Can drop to 30 bytes by moving the subtraction:function(x,y)(x-y)%in%(-1:1*5)
, and drop it further to 24 bytes by dropping the function notation toscan()
input:diff(scan())%in%(-1:1*5)
Try it online!. Still very much the same method though.
$endgroup$
– CriminallyVulgar
Jan 17 at 14:38
1
$begingroup$
@CriminallyVulgar does that account for the sum being 5?
$endgroup$
– ArBo
Jan 17 at 15:45
$begingroup$
@ArBo Hah, missed that in the spec, and there wasn't a test case in the TIO so I just glossed over it!
$endgroup$
– CriminallyVulgar
Jan 18 at 9:39
$begingroup$
Minor change that can be made to both is to usepryr::f
, which happens to work in both cases. Whether it can properly detect the arguments is entirely somewhat hit or miss but it seems to nail these two functions. e.g.pryr::f(x%in%c(y--1:1*5,5-y))
Try it online!. Gets you to 36 and 29 bytes respectively.
$endgroup$
– CriminallyVulgar
Jan 18 at 15:50
add a comment |
$begingroup$
The 34 byte one can be reduced by 1 withfunction(x,y)x%in%c(y--1:1*5,5-y)
$endgroup$
– MickyT
Jan 16 at 21:36
$begingroup$
Can drop to 30 bytes by moving the subtraction:function(x,y)(x-y)%in%(-1:1*5)
, and drop it further to 24 bytes by dropping the function notation toscan()
input:diff(scan())%in%(-1:1*5)
Try it online!. Still very much the same method though.
$endgroup$
– CriminallyVulgar
Jan 17 at 14:38
1
$begingroup$
@CriminallyVulgar does that account for the sum being 5?
$endgroup$
– ArBo
Jan 17 at 15:45
$begingroup$
@ArBo Hah, missed that in the spec, and there wasn't a test case in the TIO so I just glossed over it!
$endgroup$
– CriminallyVulgar
Jan 18 at 9:39
$begingroup$
Minor change that can be made to both is to usepryr::f
, which happens to work in both cases. Whether it can properly detect the arguments is entirely somewhat hit or miss but it seems to nail these two functions. e.g.pryr::f(x%in%c(y--1:1*5,5-y))
Try it online!. Gets you to 36 and 29 bytes respectively.
$endgroup$
– CriminallyVulgar
Jan 18 at 15:50
$begingroup$
The 34 byte one can be reduced by 1 with
function(x,y)x%in%c(y--1:1*5,5-y)
$endgroup$
– MickyT
Jan 16 at 21:36
$begingroup$
The 34 byte one can be reduced by 1 with
function(x,y)x%in%c(y--1:1*5,5-y)
$endgroup$
– MickyT
Jan 16 at 21:36
$begingroup$
Can drop to 30 bytes by moving the subtraction:
function(x,y)(x-y)%in%(-1:1*5)
, and drop it further to 24 bytes by dropping the function notation to scan()
input: diff(scan())%in%(-1:1*5)
Try it online!. Still very much the same method though.$endgroup$
– CriminallyVulgar
Jan 17 at 14:38
$begingroup$
Can drop to 30 bytes by moving the subtraction:
function(x,y)(x-y)%in%(-1:1*5)
, and drop it further to 24 bytes by dropping the function notation to scan()
input: diff(scan())%in%(-1:1*5)
Try it online!. Still very much the same method though.$endgroup$
– CriminallyVulgar
Jan 17 at 14:38
1
1
$begingroup$
@CriminallyVulgar does that account for the sum being 5?
$endgroup$
– ArBo
Jan 17 at 15:45
$begingroup$
@CriminallyVulgar does that account for the sum being 5?
$endgroup$
– ArBo
Jan 17 at 15:45
$begingroup$
@ArBo Hah, missed that in the spec, and there wasn't a test case in the TIO so I just glossed over it!
$endgroup$
– CriminallyVulgar
Jan 18 at 9:39
$begingroup$
@ArBo Hah, missed that in the spec, and there wasn't a test case in the TIO so I just glossed over it!
$endgroup$
– CriminallyVulgar
Jan 18 at 9:39
$begingroup$
Minor change that can be made to both is to use
pryr::f
, which happens to work in both cases. Whether it can properly detect the arguments is entirely somewhat hit or miss but it seems to nail these two functions. e.g. pryr::f(x%in%c(y--1:1*5,5-y))
Try it online!. Gets you to 36 and 29 bytes respectively.$endgroup$
– CriminallyVulgar
Jan 18 at 15:50
$begingroup$
Minor change that can be made to both is to use
pryr::f
, which happens to work in both cases. Whether it can properly detect the arguments is entirely somewhat hit or miss but it seems to nail these two functions. e.g. pryr::f(x%in%c(y--1:1*5,5-y))
Try it online!. Gets you to 36 and 29 bytes respectively.$endgroup$
– CriminallyVulgar
Jan 18 at 15:50
add a comment |
$begingroup$
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.
$endgroup$
add a comment |
$begingroup$
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.
$endgroup$
add a comment |
$begingroup$
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.
$endgroup$
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.
edited Jan 17 at 12:00
answered Jan 16 at 18:31
Kirill L.Kirill L.
4,4651523
4,4651523
add a comment |
add a comment |
$begingroup$
8086 machine code, 22 20 bytes
8bd0 2bc3 740e 7902 f7d8 3d0500 7405 03d3 83fa05
Ungolfed:
ESD MACRO
LOCAL SUB_POS, DONE
MOV DX, AX ; Save AX to DX
SUB AX, BX ; AX = AX - BX
JZ DONE ; if 0, then they are equal, ZF=1
JNS SUB_POS ; if positive, go to SUB_POS
NEG AX ; otherwise negate the result
SUB_POS:
CMP AX, 5 ; if result is 5, ZF=1
JZ DONE
ADD DX, BX ; DX = DX + BX
CMP DX, 5 ; if 5, ZF=1
DONE:
ENDM
Input numbers in AX and BX and returns Zero Flag (ZF=1) if result is true. If desired, you can also determine which condition was true with the following:
- ZF = 1 and DX = 5 ; sum is 5
- ZF = 1 and AX = 5 ; diff is 5
- ZF = 1 and AX = 0 ; equal
- ZF = 0 ; result false
If the difference between the numbers is 0, we know they are equal. Otherwise if result is negative, then first negate it and then check for 5. If still not true, then add and check for 5.
Sample PC DOS test program. Download it here (ESD.COM).
START:
CALL INDEC ; input first number into AX
MOV BX, AX ; move to BX
CALL INDEC ; input second number into BX
ESD ; run "Equal, sum or difference" routine
JZ TRUE ; if ZF=1, result is true
FALSE:
MOV DX, OFFSET FALSY ; load Falsy string
JMP DONE
TRUE:
MOV DX, OFFSET TRUTHY ; load Truthy string
DONE:
MOV AH, 9 ; DOS display string
INT 21H ; execute
MOV AX, 4C00H ; DOS terminate
INT 21H ; execute
TRUTHY DB 'Truthy$'
FALSY DB 'Falsy$'
INCLUDE INDEC.ASM ; generic decimal input prompt routine
Output of test program:
A>ESD.COM
: 4
: 1
Truthy
A>ESD.COM
: 10
: 10
Truthy
A>ESD.COM
: 1
: 3
Falsy
A>ESD.COM
: 6
: 2
Falsy
A>ESD.COM
: 1
: 6
Truthy
A>ESD.COM
: -256
: -251
Truthy
A>ESD.COM
: 6
: 1
Truthy
A>ESD.COM
: 9999999999
: 9999999994
Truthy
$endgroup$
add a comment |
$begingroup$
8086 machine code, 22 20 bytes
8bd0 2bc3 740e 7902 f7d8 3d0500 7405 03d3 83fa05
Ungolfed:
ESD MACRO
LOCAL SUB_POS, DONE
MOV DX, AX ; Save AX to DX
SUB AX, BX ; AX = AX - BX
JZ DONE ; if 0, then they are equal, ZF=1
JNS SUB_POS ; if positive, go to SUB_POS
NEG AX ; otherwise negate the result
SUB_POS:
CMP AX, 5 ; if result is 5, ZF=1
JZ DONE
ADD DX, BX ; DX = DX + BX
CMP DX, 5 ; if 5, ZF=1
DONE:
ENDM
Input numbers in AX and BX and returns Zero Flag (ZF=1) if result is true. If desired, you can also determine which condition was true with the following:
- ZF = 1 and DX = 5 ; sum is 5
- ZF = 1 and AX = 5 ; diff is 5
- ZF = 1 and AX = 0 ; equal
- ZF = 0 ; result false
If the difference between the numbers is 0, we know they are equal. Otherwise if result is negative, then first negate it and then check for 5. If still not true, then add and check for 5.
Sample PC DOS test program. Download it here (ESD.COM).
START:
CALL INDEC ; input first number into AX
MOV BX, AX ; move to BX
CALL INDEC ; input second number into BX
ESD ; run "Equal, sum or difference" routine
JZ TRUE ; if ZF=1, result is true
FALSE:
MOV DX, OFFSET FALSY ; load Falsy string
JMP DONE
TRUE:
MOV DX, OFFSET TRUTHY ; load Truthy string
DONE:
MOV AH, 9 ; DOS display string
INT 21H ; execute
MOV AX, 4C00H ; DOS terminate
INT 21H ; execute
TRUTHY DB 'Truthy$'
FALSY DB 'Falsy$'
INCLUDE INDEC.ASM ; generic decimal input prompt routine
Output of test program:
A>ESD.COM
: 4
: 1
Truthy
A>ESD.COM
: 10
: 10
Truthy
A>ESD.COM
: 1
: 3
Falsy
A>ESD.COM
: 6
: 2
Falsy
A>ESD.COM
: 1
: 6
Truthy
A>ESD.COM
: -256
: -251
Truthy
A>ESD.COM
: 6
: 1
Truthy
A>ESD.COM
: 9999999999
: 9999999994
Truthy
$endgroup$
add a comment |
$begingroup$
8086 machine code, 22 20 bytes
8bd0 2bc3 740e 7902 f7d8 3d0500 7405 03d3 83fa05
Ungolfed:
ESD MACRO
LOCAL SUB_POS, DONE
MOV DX, AX ; Save AX to DX
SUB AX, BX ; AX = AX - BX
JZ DONE ; if 0, then they are equal, ZF=1
JNS SUB_POS ; if positive, go to SUB_POS
NEG AX ; otherwise negate the result
SUB_POS:
CMP AX, 5 ; if result is 5, ZF=1
JZ DONE
ADD DX, BX ; DX = DX + BX
CMP DX, 5 ; if 5, ZF=1
DONE:
ENDM
Input numbers in AX and BX and returns Zero Flag (ZF=1) if result is true. If desired, you can also determine which condition was true with the following:
- ZF = 1 and DX = 5 ; sum is 5
- ZF = 1 and AX = 5 ; diff is 5
- ZF = 1 and AX = 0 ; equal
- ZF = 0 ; result false
If the difference between the numbers is 0, we know they are equal. Otherwise if result is negative, then first negate it and then check for 5. If still not true, then add and check for 5.
Sample PC DOS test program. Download it here (ESD.COM).
START:
CALL INDEC ; input first number into AX
MOV BX, AX ; move to BX
CALL INDEC ; input second number into BX
ESD ; run "Equal, sum or difference" routine
JZ TRUE ; if ZF=1, result is true
FALSE:
MOV DX, OFFSET FALSY ; load Falsy string
JMP DONE
TRUE:
MOV DX, OFFSET TRUTHY ; load Truthy string
DONE:
MOV AH, 9 ; DOS display string
INT 21H ; execute
MOV AX, 4C00H ; DOS terminate
INT 21H ; execute
TRUTHY DB 'Truthy$'
FALSY DB 'Falsy$'
INCLUDE INDEC.ASM ; generic decimal input prompt routine
Output of test program:
A>ESD.COM
: 4
: 1
Truthy
A>ESD.COM
: 10
: 10
Truthy
A>ESD.COM
: 1
: 3
Falsy
A>ESD.COM
: 6
: 2
Falsy
A>ESD.COM
: 1
: 6
Truthy
A>ESD.COM
: -256
: -251
Truthy
A>ESD.COM
: 6
: 1
Truthy
A>ESD.COM
: 9999999999
: 9999999994
Truthy
$endgroup$
8086 machine code, 22 20 bytes
8bd0 2bc3 740e 7902 f7d8 3d0500 7405 03d3 83fa05
Ungolfed:
ESD MACRO
LOCAL SUB_POS, DONE
MOV DX, AX ; Save AX to DX
SUB AX, BX ; AX = AX - BX
JZ DONE ; if 0, then they are equal, ZF=1
JNS SUB_POS ; if positive, go to SUB_POS
NEG AX ; otherwise negate the result
SUB_POS:
CMP AX, 5 ; if result is 5, ZF=1
JZ DONE
ADD DX, BX ; DX = DX + BX
CMP DX, 5 ; if 5, ZF=1
DONE:
ENDM
Input numbers in AX and BX and returns Zero Flag (ZF=1) if result is true. If desired, you can also determine which condition was true with the following:
- ZF = 1 and DX = 5 ; sum is 5
- ZF = 1 and AX = 5 ; diff is 5
- ZF = 1 and AX = 0 ; equal
- ZF = 0 ; result false
If the difference between the numbers is 0, we know they are equal. Otherwise if result is negative, then first negate it and then check for 5. If still not true, then add and check for 5.
Sample PC DOS test program. Download it here (ESD.COM).
START:
CALL INDEC ; input first number into AX
MOV BX, AX ; move to BX
CALL INDEC ; input second number into BX
ESD ; run "Equal, sum or difference" routine
JZ TRUE ; if ZF=1, result is true
FALSE:
MOV DX, OFFSET FALSY ; load Falsy string
JMP DONE
TRUE:
MOV DX, OFFSET TRUTHY ; load Truthy string
DONE:
MOV AH, 9 ; DOS display string
INT 21H ; execute
MOV AX, 4C00H ; DOS terminate
INT 21H ; execute
TRUTHY DB 'Truthy$'
FALSY DB 'Falsy$'
INCLUDE INDEC.ASM ; generic decimal input prompt routine
Output of test program:
A>ESD.COM
: 4
: 1
Truthy
A>ESD.COM
: 10
: 10
Truthy
A>ESD.COM
: 1
: 3
Falsy
A>ESD.COM
: 6
: 2
Falsy
A>ESD.COM
: 1
: 6
Truthy
A>ESD.COM
: -256
: -251
Truthy
A>ESD.COM
: 6
: 1
Truthy
A>ESD.COM
: 9999999999
: 9999999994
Truthy
edited Jan 18 at 18:51
answered Jan 17 at 4:45


gwaughgwaugh
1,235513
1,235513
add a comment |
add a comment |
$begingroup$
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 fi 5 exists in the pair.
= Test x and y for equality.
o Logical OR.
$endgroup$
add a comment |
$begingroup$
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 fi 5 exists in the pair.
= Test x and y for equality.
o Logical OR.
$endgroup$
add a comment |
$begingroup$
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 fi 5 exists in the pair.
= Test x and y for equality.
o Logical OR.
$endgroup$
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 fi 5 exists in the pair.
= Test x and y for equality.
o Logical OR.
answered Jan 16 at 16:22


Dennis♦Dennis
188k32299739
188k32299739
add a comment |
add a comment |
$begingroup$
Python 2, 38 bytes
-2 bytes thanks to @DjMcMayhem
lambda a,b:a+b==5or abs(a-b)==5or a==b
Try it online!
$endgroup$
$begingroup$
Your TIO is actually 42 bytes but you can fix it by deleting the spaces between the5
s and theor
s
$endgroup$
– ElPedro
Jan 16 at 16:12
3
$begingroup$
Actually, the TIO link could be 38 bytes
$endgroup$
– DJMcMayhem♦
Jan 16 at 16:14
$begingroup$
@ElPedro the function itself was 40 bytes but I used f= in order to be able to call it
$endgroup$
– fəˈnɛtɪk
Jan 16 at 18:10
1
$begingroup$
@DJMcMayhem I don't normally golf in python. I just did it because the question asker used python for their example
$endgroup$
– fəˈnɛtɪk
Jan 16 at 18:12
add a comment |
$begingroup$
Python 2, 38 bytes
-2 bytes thanks to @DjMcMayhem
lambda a,b:a+b==5or abs(a-b)==5or a==b
Try it online!
$endgroup$
$begingroup$
Your TIO is actually 42 bytes but you can fix it by deleting the spaces between the5
s and theor
s
$endgroup$
– ElPedro
Jan 16 at 16:12
3
$begingroup$
Actually, the TIO link could be 38 bytes
$endgroup$
– DJMcMayhem♦
Jan 16 at 16:14
$begingroup$
@ElPedro the function itself was 40 bytes but I used f= in order to be able to call it
$endgroup$
– fəˈnɛtɪk
Jan 16 at 18:10
1
$begingroup$
@DJMcMayhem I don't normally golf in python. I just did it because the question asker used python for their example
$endgroup$
– fəˈnɛtɪk
Jan 16 at 18:12
add a comment |
$begingroup$
Python 2, 38 bytes
-2 bytes thanks to @DjMcMayhem
lambda a,b:a+b==5or abs(a-b)==5or a==b
Try it online!
$endgroup$
Python 2, 38 bytes
-2 bytes thanks to @DjMcMayhem
lambda a,b:a+b==5or abs(a-b)==5or a==b
Try it online!
edited Jan 16 at 18:11
answered Jan 16 at 16:09


fəˈnɛtɪkfəˈnɛtɪk
3,6611637
3,6611637
$begingroup$
Your TIO is actually 42 bytes but you can fix it by deleting the spaces between the5
s and theor
s
$endgroup$
– ElPedro
Jan 16 at 16:12
3
$begingroup$
Actually, the TIO link could be 38 bytes
$endgroup$
– DJMcMayhem♦
Jan 16 at 16:14
$begingroup$
@ElPedro the function itself was 40 bytes but I used f= in order to be able to call it
$endgroup$
– fəˈnɛtɪk
Jan 16 at 18:10
1
$begingroup$
@DJMcMayhem I don't normally golf in python. I just did it because the question asker used python for their example
$endgroup$
– fəˈnɛtɪk
Jan 16 at 18:12
add a comment |
$begingroup$
Your TIO is actually 42 bytes but you can fix it by deleting the spaces between the5
s and theor
s
$endgroup$
– ElPedro
Jan 16 at 16:12
3
$begingroup$
Actually, the TIO link could be 38 bytes
$endgroup$
– DJMcMayhem♦
Jan 16 at 16:14
$begingroup$
@ElPedro the function itself was 40 bytes but I used f= in order to be able to call it
$endgroup$
– fəˈnɛtɪk
Jan 16 at 18:10
1
$begingroup$
@DJMcMayhem I don't normally golf in python. I just did it because the question asker used python for their example
$endgroup$
– fəˈnɛtɪk
Jan 16 at 18:12
$begingroup$
Your TIO is actually 42 bytes but you can fix it by deleting the spaces between the
5
s and the or
s$endgroup$
– ElPedro
Jan 16 at 16:12
$begingroup$
Your TIO is actually 42 bytes but you can fix it by deleting the spaces between the
5
s and the or
s$endgroup$
– ElPedro
Jan 16 at 16:12
3
3
$begingroup$
Actually, the TIO link could be 38 bytes
$endgroup$
– DJMcMayhem♦
Jan 16 at 16:14
$begingroup$
Actually, the TIO link could be 38 bytes
$endgroup$
– DJMcMayhem♦
Jan 16 at 16:14
$begingroup$
@ElPedro the function itself was 40 bytes but I used f= in order to be able to call it
$endgroup$
– fəˈnɛtɪk
Jan 16 at 18:10
$begingroup$
@ElPedro the function itself was 40 bytes but I used f= in order to be able to call it
$endgroup$
– fəˈnɛtɪk
Jan 16 at 18:10
1
1
$begingroup$
@DJMcMayhem I don't normally golf in python. I just did it because the question asker used python for their example
$endgroup$
– fəˈnɛtɪk
Jan 16 at 18:12
$begingroup$
@DJMcMayhem I don't normally golf in python. I just did it because the question asker used python for their example
$endgroup$
– fəˈnɛtɪk
Jan 16 at 18:12
add a comment |
$begingroup$
Java (JDK), 30 bytes
a->b->a+b==5|a==b|(b-=a)*b==25
Try it online!
$endgroup$
add a comment |
$begingroup$
Java (JDK), 30 bytes
a->b->a+b==5|a==b|(b-=a)*b==25
Try it online!
$endgroup$
add a comment |
$begingroup$
Java (JDK), 30 bytes
a->b->a+b==5|a==b|(b-=a)*b==25
Try it online!
$endgroup$
Java (JDK), 30 bytes
a->b->a+b==5|a==b|(b-=a)*b==25
Try it online!
answered Jan 16 at 21:40


Olivier GrégoireOlivier Grégoire
9,10511943
9,10511943
add a comment |
add a comment |
$begingroup$
Wolfram Language (Mathematica), 22 bytes
Takes input as [a][b]
.
MatchQ[#|5-#|#-5|#+5]&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 22 bytes
Takes input as [a][b]
.
MatchQ[#|5-#|#-5|#+5]&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 22 bytes
Takes input as [a][b]
.
MatchQ[#|5-#|#-5|#+5]&
Try it online!
$endgroup$
Wolfram Language (Mathematica), 22 bytes
Takes input as [a][b]
.
MatchQ[#|5-#|#-5|#+5]&
Try it online!
edited Jan 17 at 5:07
answered Jan 16 at 16:49
alephalphaalephalpha
21.3k32991
21.3k32991
add a comment |
add a comment |
$begingroup$
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.
$endgroup$
$begingroup$
($a-$b)
is-$x
:)
$endgroup$
– mazzy
Jan 16 at 17:14
$begingroup$
@mazzy Ooo, good call.
$endgroup$
– AdmBorkBork
Jan 16 at 17:41
$begingroup$
If you switch5
and$b
around you can cut off a couple bytes(ieparam($a,$b)$b-in($a-5),(5-$a),($a+5),$a
) Try it out here
$endgroup$
– KGlasier
Jan 17 at 15:13
1
$begingroup$
@KGlasier Excellent suggestion. I needed to swap$a+5
to5+$a
to get it to cast appropriately when taking command-line input, but otherwise awesome. Thanks!
$endgroup$
– AdmBorkBork
Jan 17 at 15:55
add a comment |
$begingroup$
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.
$endgroup$
$begingroup$
($a-$b)
is-$x
:)
$endgroup$
– mazzy
Jan 16 at 17:14
$begingroup$
@mazzy Ooo, good call.
$endgroup$
– AdmBorkBork
Jan 16 at 17:41
$begingroup$
If you switch5
and$b
around you can cut off a couple bytes(ieparam($a,$b)$b-in($a-5),(5-$a),($a+5),$a
) Try it out here
$endgroup$
– KGlasier
Jan 17 at 15:13
1
$begingroup$
@KGlasier Excellent suggestion. I needed to swap$a+5
to5+$a
to get it to cast appropriately when taking command-line input, but otherwise awesome. Thanks!
$endgroup$
– AdmBorkBork
Jan 17 at 15:55
add a comment |
$begingroup$
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.
$endgroup$
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.
edited Jan 17 at 15:54
answered Jan 16 at 16:28


AdmBorkBorkAdmBorkBork
27.3k466236
27.3k466236
$begingroup$
($a-$b)
is-$x
:)
$endgroup$
– mazzy
Jan 16 at 17:14
$begingroup$
@mazzy Ooo, good call.
$endgroup$
– AdmBorkBork
Jan 16 at 17:41
$begingroup$
If you switch5
and$b
around you can cut off a couple bytes(ieparam($a,$b)$b-in($a-5),(5-$a),($a+5),$a
) Try it out here
$endgroup$
– KGlasier
Jan 17 at 15:13
1
$begingroup$
@KGlasier Excellent suggestion. I needed to swap$a+5
to5+$a
to get it to cast appropriately when taking command-line input, but otherwise awesome. Thanks!
$endgroup$
– AdmBorkBork
Jan 17 at 15:55
add a comment |
$begingroup$
($a-$b)
is-$x
:)
$endgroup$
– mazzy
Jan 16 at 17:14
$begingroup$
@mazzy Ooo, good call.
$endgroup$
– AdmBorkBork
Jan 16 at 17:41
$begingroup$
If you switch5
and$b
around you can cut off a couple bytes(ieparam($a,$b)$b-in($a-5),(5-$a),($a+5),$a
) Try it out here
$endgroup$
– KGlasier
Jan 17 at 15:13
1
$begingroup$
@KGlasier Excellent suggestion. I needed to swap$a+5
to5+$a
to get it to cast appropriately when taking command-line input, but otherwise awesome. Thanks!
$endgroup$
– AdmBorkBork
Jan 17 at 15:55
$begingroup$
($a-$b)
is -$x
:)$endgroup$
– mazzy
Jan 16 at 17:14
$begingroup$
($a-$b)
is -$x
:)$endgroup$
– mazzy
Jan 16 at 17:14
$begingroup$
@mazzy Ooo, good call.
$endgroup$
– AdmBorkBork
Jan 16 at 17:41
$begingroup$
@mazzy Ooo, good call.
$endgroup$
– AdmBorkBork
Jan 16 at 17:41
$begingroup$
If you switch
5
and $b
around you can cut off a couple bytes(ie param($a,$b)$b-in($a-5),(5-$a),($a+5),$a
) Try it out here$endgroup$
– KGlasier
Jan 17 at 15:13
$begingroup$
If you switch
5
and $b
around you can cut off a couple bytes(ie param($a,$b)$b-in($a-5),(5-$a),($a+5),$a
) Try it out here$endgroup$
– KGlasier
Jan 17 at 15:13
1
1
$begingroup$
@KGlasier Excellent suggestion. I needed to swap
$a+5
to 5+$a
to get it to cast appropriately when taking command-line input, but otherwise awesome. Thanks!$endgroup$
– AdmBorkBork
Jan 17 at 15:55
$begingroup$
@KGlasier Excellent suggestion. I needed to swap
$a+5
to 5+$a
to get it to cast appropriately when taking command-line input, but otherwise awesome. Thanks!$endgroup$
– AdmBorkBork
Jan 17 at 15:55
add a comment |
$begingroup$
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.
$endgroup$
2
$begingroup$
Hello, and welcome to PPCG! Normally, you have to take input, instead of assuming it is already in variables. I don't know Pascal, but I think that is what this code is doing.
$endgroup$
– NoOneIsHere
Jan 20 at 17:42
$begingroup$
Hello, NoOneIsHere and thank you for the remark. It was may concern too - shall I include the initialization of the variables. Looking at several other solutions, like Java for example, where the function definition with parameters was excluded from the total length of the solution, I decided not to include ReadLn.
$endgroup$
– Dessy Stoeva
Jan 20 at 18:42
$begingroup$
Alright. Welcome to PPCG!
$endgroup$
– NoOneIsHere
Jan 20 at 23:47
$begingroup$
The Java submission is an anonymous lambda which takes two parameters. This appears to use predefined variables, which is not a valid method of input.
$endgroup$
– Jo King
Jan 24 at 11:08
1
$begingroup$
No problem, I will change my submission.
$endgroup$
– Dessy Stoeva
Jan 24 at 13:55
add a comment |
$begingroup$
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.
$endgroup$
2
$begingroup$
Hello, and welcome to PPCG! Normally, you have to take input, instead of assuming it is already in variables. I don't know Pascal, but I think that is what this code is doing.
$endgroup$
– NoOneIsHere
Jan 20 at 17:42
$begingroup$
Hello, NoOneIsHere and thank you for the remark. It was may concern too - shall I include the initialization of the variables. Looking at several other solutions, like Java for example, where the function definition with parameters was excluded from the total length of the solution, I decided not to include ReadLn.
$endgroup$
– Dessy Stoeva
Jan 20 at 18:42
$begingroup$
Alright. Welcome to PPCG!
$endgroup$
– NoOneIsHere
Jan 20 at 23:47
$begingroup$
The Java submission is an anonymous lambda which takes two parameters. This appears to use predefined variables, which is not a valid method of input.
$endgroup$
– Jo King
Jan 24 at 11:08
1
$begingroup$
No problem, I will change my submission.
$endgroup$
– Dessy Stoeva
Jan 24 at 13:55
add a comment |
$begingroup$
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.
$endgroup$
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.
edited Jan 28 at 22:04
answered Jan 20 at 17:24
Dessy StoevaDessy Stoeva
413
413
2
$begingroup$
Hello, and welcome to PPCG! Normally, you have to take input, instead of assuming it is already in variables. I don't know Pascal, but I think that is what this code is doing.
$endgroup$
– NoOneIsHere
Jan 20 at 17:42
$begingroup$
Hello, NoOneIsHere and thank you for the remark. It was may concern too - shall I include the initialization of the variables. Looking at several other solutions, like Java for example, where the function definition with parameters was excluded from the total length of the solution, I decided not to include ReadLn.
$endgroup$
– Dessy Stoeva
Jan 20 at 18:42
$begingroup$
Alright. Welcome to PPCG!
$endgroup$
– NoOneIsHere
Jan 20 at 23:47
$begingroup$
The Java submission is an anonymous lambda which takes two parameters. This appears to use predefined variables, which is not a valid method of input.
$endgroup$
– Jo King
Jan 24 at 11:08
1
$begingroup$
No problem, I will change my submission.
$endgroup$
– Dessy Stoeva
Jan 24 at 13:55
add a comment |
2
$begingroup$
Hello, and welcome to PPCG! Normally, you have to take input, instead of assuming it is already in variables. I don't know Pascal, but I think that is what this code is doing.
$endgroup$
– NoOneIsHere
Jan 20 at 17:42
$begingroup$
Hello, NoOneIsHere and thank you for the remark. It was may concern too - shall I include the initialization of the variables. Looking at several other solutions, like Java for example, where the function definition with parameters was excluded from the total length of the solution, I decided not to include ReadLn.
$endgroup$
– Dessy Stoeva
Jan 20 at 18:42
$begingroup$
Alright. Welcome to PPCG!
$endgroup$
– NoOneIsHere
Jan 20 at 23:47
$begingroup$
The Java submission is an anonymous lambda which takes two parameters. This appears to use predefined variables, which is not a valid method of input.
$endgroup$
– Jo King
Jan 24 at 11:08
1
$begingroup$
No problem, I will change my submission.
$endgroup$
– Dessy Stoeva
Jan 24 at 13:55
2
2
$begingroup$
Hello, and welcome to PPCG! Normally, you have to take input, instead of assuming it is already in variables. I don't know Pascal, but I think that is what this code is doing.
$endgroup$
– NoOneIsHere
Jan 20 at 17:42
$begingroup$
Hello, and welcome to PPCG! Normally, you have to take input, instead of assuming it is already in variables. I don't know Pascal, but I think that is what this code is doing.
$endgroup$
– NoOneIsHere
Jan 20 at 17:42
$begingroup$
Hello, NoOneIsHere and thank you for the remark. It was may concern too - shall I include the initialization of the variables. Looking at several other solutions, like Java for example, where the function definition with parameters was excluded from the total length of the solution, I decided not to include ReadLn.
$endgroup$
– Dessy Stoeva
Jan 20 at 18:42
$begingroup$
Hello, NoOneIsHere and thank you for the remark. It was may concern too - shall I include the initialization of the variables. Looking at several other solutions, like Java for example, where the function definition with parameters was excluded from the total length of the solution, I decided not to include ReadLn.
$endgroup$
– Dessy Stoeva
Jan 20 at 18:42
$begingroup$
Alright. Welcome to PPCG!
$endgroup$
– NoOneIsHere
Jan 20 at 23:47
$begingroup$
Alright. Welcome to PPCG!
$endgroup$
– NoOneIsHere
Jan 20 at 23:47
$begingroup$
The Java submission is an anonymous lambda which takes two parameters. This appears to use predefined variables, which is not a valid method of input.
$endgroup$
– Jo King
Jan 24 at 11:08
$begingroup$
The Java submission is an anonymous lambda which takes two parameters. This appears to use predefined variables, which is not a valid method of input.
$endgroup$
– Jo King
Jan 24 at 11:08
1
1
$begingroup$
No problem, I will change my submission.
$endgroup$
– Dessy Stoeva
Jan 24 at 13:55
$begingroup$
No problem, I will change my submission.
$endgroup$
– Dessy Stoeva
Jan 24 at 13:55
add a comment |
$begingroup$
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!
$endgroup$
$begingroup$
Bah. Trying to avoid System.Math. Back to it! Thanks for pointing that out :D
$endgroup$
– Destroigo
Jan 16 at 16:41
1
$begingroup$
You can get it down to 33 bytes applying dana's tips
$endgroup$
– Embodiment of Ignorance
Jan 16 at 18:10
add a comment |
$begingroup$
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!
$endgroup$
$begingroup$
Bah. Trying to avoid System.Math. Back to it! Thanks for pointing that out :D
$endgroup$
– Destroigo
Jan 16 at 16:41
1
$begingroup$
You can get it down to 33 bytes applying dana's tips
$endgroup$
– Embodiment of Ignorance
Jan 16 at 18:10
add a comment |
$begingroup$
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!
$endgroup$
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!
edited Jan 16 at 19:00
answered Jan 16 at 16:32
DestroigoDestroigo
3916
3916
$begingroup$
Bah. Trying to avoid System.Math. Back to it! Thanks for pointing that out :D
$endgroup$
– Destroigo
Jan 16 at 16:41
1
$begingroup$
You can get it down to 33 bytes applying dana's tips
$endgroup$
– Embodiment of Ignorance
Jan 16 at 18:10
add a comment |
$begingroup$
Bah. Trying to avoid System.Math. Back to it! Thanks for pointing that out :D
$endgroup$
– Destroigo
Jan 16 at 16:41
1
$begingroup$
You can get it down to 33 bytes applying dana's tips
$endgroup$
– Embodiment of Ignorance
Jan 16 at 18:10
$begingroup$
Bah. Trying to avoid System.Math. Back to it! Thanks for pointing that out :D
$endgroup$
– Destroigo
Jan 16 at 16:41
$begingroup$
Bah. Trying to avoid System.Math. Back to it! Thanks for pointing that out :D
$endgroup$
– Destroigo
Jan 16 at 16:41
1
1
$begingroup$
You can get it down to 33 bytes applying dana's tips
$endgroup$
– Embodiment of Ignorance
Jan 16 at 18:10
$begingroup$
You can get it down to 33 bytes applying dana's tips
$endgroup$
– Embodiment of Ignorance
Jan 16 at 18:10
add a comment |
$begingroup$
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)
.
$endgroup$
add a comment |
$begingroup$
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)
.
$endgroup$
add a comment |
$begingroup$
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)
.
$endgroup$
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)
.
answered Jan 17 at 5:49
attinatattinat
3405
3405
add a comment |
add a comment |
$begingroup$
Scala, 43 bytes
def f(a:Int,b:Int)=a+b==5|(a-b).abs==5|a==b
Try it online!
$endgroup$
$begingroup$
Isn't it possible to golf the||
to|
? I know it's possible in Java, C#, Python, or JavaScript, but not sure about Scala.
$endgroup$
– Kevin Cruijssen
Jan 17 at 12:15
$begingroup$
Actually yes! thanks
$endgroup$
– Xavier Guihot
Jan 17 at 12:18
add a comment |
$begingroup$
Scala, 43 bytes
def f(a:Int,b:Int)=a+b==5|(a-b).abs==5|a==b
Try it online!
$endgroup$
$begingroup$
Isn't it possible to golf the||
to|
? I know it's possible in Java, C#, Python, or JavaScript, but not sure about Scala.
$endgroup$
– Kevin Cruijssen
Jan 17 at 12:15
$begingroup$
Actually yes! thanks
$endgroup$
– Xavier Guihot
Jan 17 at 12:18
add a comment |
$begingroup$
Scala, 43 bytes
def f(a:Int,b:Int)=a+b==5|(a-b).abs==5|a==b
Try it online!
$endgroup$
Scala, 43 bytes
def f(a:Int,b:Int)=a+b==5|(a-b).abs==5|a==b
Try it online!
edited Jan 17 at 12:18
answered Jan 16 at 16:51


Xavier GuihotXavier Guihot
2237
2237
$begingroup$
Isn't it possible to golf the||
to|
? I know it's possible in Java, C#, Python, or JavaScript, but not sure about Scala.
$endgroup$
– Kevin Cruijssen
Jan 17 at 12:15
$begingroup$
Actually yes! thanks
$endgroup$
– Xavier Guihot
Jan 17 at 12:18
add a comment |
$begingroup$
Isn't it possible to golf the||
to|
? I know it's possible in Java, C#, Python, or JavaScript, but not sure about Scala.
$endgroup$
– Kevin Cruijssen
Jan 17 at 12:15
$begingroup$
Actually yes! thanks
$endgroup$
– Xavier Guihot
Jan 17 at 12:18
$begingroup$
Isn't it possible to golf the
||
to |
? I know it's possible in Java, C#, Python, or JavaScript, but not sure about Scala.$endgroup$
– Kevin Cruijssen
Jan 17 at 12:15
$begingroup$
Isn't it possible to golf the
||
to |
? I know it's possible in Java, C#, Python, or JavaScript, but not sure about Scala.$endgroup$
– Kevin Cruijssen
Jan 17 at 12:15
$begingroup$
Actually yes! thanks
$endgroup$
– Xavier Guihot
Jan 17 at 12:18
$begingroup$
Actually yes! thanks
$endgroup$
– Xavier Guihot
Jan 17 at 12:18
add a comment |
$begingroup$
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
$endgroup$
1
$begingroup$
-1 byte with{$^a-$^b==5|0|-5|5-2*$b}
$endgroup$
– Grimy
Jan 17 at 15:00
add a comment |
$begingroup$
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
$endgroup$
1
$begingroup$
-1 byte with{$^a-$^b==5|0|-5|5-2*$b}
$endgroup$
– Grimy
Jan 17 at 15:00
add a comment |
$begingroup$
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
$endgroup$
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
edited Jan 17 at 22:43
answered Jan 17 at 1:42
Jo KingJo King
23.3k254121
23.3k254121
1
$begingroup$
-1 byte with{$^a-$^b==5|0|-5|5-2*$b}
$endgroup$
– Grimy
Jan 17 at 15:00
add a comment |
1
$begingroup$
-1 byte with{$^a-$^b==5|0|-5|5-2*$b}
$endgroup$
– Grimy
Jan 17 at 15:00
1
1
$begingroup$
-1 byte with
{$^a-$^b==5|0|-5|5-2*$b}
$endgroup$
– Grimy
Jan 17 at 15:00
$begingroup$
-1 byte with
{$^a-$^b==5|0|-5|5-2*$b}
$endgroup$
– Grimy
Jan 17 at 15:00
add a comment |
$begingroup$
C (gcc), 41 34 bytes
f(a,b){a=5==abs(a-b)|a+b==5|a==b;}
Try it online!
$endgroup$
1
$begingroup$
Why doesf
returna
? Just some Undefined Behavior?
$endgroup$
– Tyilo
Jan 16 at 17:05
$begingroup$
@Tyilo Yes, it's implementation specific. So happens the first parameter is stored in the same register as the return value.
$endgroup$
– cleblanc
Jan 16 at 17:07
$begingroup$
30 bytes Try it online!
$endgroup$
– Logern
Jan 16 at 18:02
$begingroup$
@Logern Doesn't work for f(6,1)
$endgroup$
– cleblanc
Jan 16 at 18:31
$begingroup$
@ceilingcat Doesn't work for f(6,1)
$endgroup$
– cleblanc
Jan 16 at 18:32
|
show 2 more comments
$begingroup$
C (gcc), 41 34 bytes
f(a,b){a=5==abs(a-b)|a+b==5|a==b;}
Try it online!
$endgroup$
1
$begingroup$
Why doesf
returna
? Just some Undefined Behavior?
$endgroup$
– Tyilo
Jan 16 at 17:05
$begingroup$
@Tyilo Yes, it's implementation specific. So happens the first parameter is stored in the same register as the return value.
$endgroup$
– cleblanc
Jan 16 at 17:07
$begingroup$
30 bytes Try it online!
$endgroup$
– Logern
Jan 16 at 18:02
$begingroup$
@Logern Doesn't work for f(6,1)
$endgroup$
– cleblanc
Jan 16 at 18:31
$begingroup$
@ceilingcat Doesn't work for f(6,1)
$endgroup$
– cleblanc
Jan 16 at 18:32
|
show 2 more comments
$begingroup$
C (gcc), 41 34 bytes
f(a,b){a=5==abs(a-b)|a+b==5|a==b;}
Try it online!
$endgroup$
C (gcc), 41 34 bytes
f(a,b){a=5==abs(a-b)|a+b==5|a==b;}
Try it online!
edited Jan 16 at 17:04
answered Jan 16 at 16:37


cleblanccleblanc
3,260316
3,260316
1
$begingroup$
Why doesf
returna
? Just some Undefined Behavior?
$endgroup$
– Tyilo
Jan 16 at 17:05
$begingroup$
@Tyilo Yes, it's implementation specific. So happens the first parameter is stored in the same register as the return value.
$endgroup$
– cleblanc
Jan 16 at 17:07
$begingroup$
30 bytes Try it online!
$endgroup$
– Logern
Jan 16 at 18:02
$begingroup$
@Logern Doesn't work for f(6,1)
$endgroup$
– cleblanc
Jan 16 at 18:31
$begingroup$
@ceilingcat Doesn't work for f(6,1)
$endgroup$
– cleblanc
Jan 16 at 18:32
|
show 2 more comments
1
$begingroup$
Why doesf
returna
? Just some Undefined Behavior?
$endgroup$
– Tyilo
Jan 16 at 17:05
$begingroup$
@Tyilo Yes, it's implementation specific. So happens the first parameter is stored in the same register as the return value.
$endgroup$
– cleblanc
Jan 16 at 17:07
$begingroup$
30 bytes Try it online!
$endgroup$
– Logern
Jan 16 at 18:02
$begingroup$
@Logern Doesn't work for f(6,1)
$endgroup$
– cleblanc
Jan 16 at 18:31
$begingroup$
@ceilingcat Doesn't work for f(6,1)
$endgroup$
– cleblanc
Jan 16 at 18:32
1
1
$begingroup$
Why does
f
return a
? Just some Undefined Behavior?$endgroup$
– Tyilo
Jan 16 at 17:05
$begingroup$
Why does
f
return a
? Just some Undefined Behavior?$endgroup$
– Tyilo
Jan 16 at 17:05
$begingroup$
@Tyilo Yes, it's implementation specific. So happens the first parameter is stored in the same register as the return value.
$endgroup$
– cleblanc
Jan 16 at 17:07
$begingroup$
@Tyilo Yes, it's implementation specific. So happens the first parameter is stored in the same register as the return value.
$endgroup$
– cleblanc
Jan 16 at 17:07
$begingroup$
30 bytes Try it online!
$endgroup$
– Logern
Jan 16 at 18:02
$begingroup$
30 bytes Try it online!
$endgroup$
– Logern
Jan 16 at 18:02
$begingroup$
@Logern Doesn't work for f(6,1)
$endgroup$
– cleblanc
Jan 16 at 18:31
$begingroup$
@Logern Doesn't work for f(6,1)
$endgroup$
– cleblanc
Jan 16 at 18:31
$begingroup$
@ceilingcat Doesn't work for f(6,1)
$endgroup$
– cleblanc
Jan 16 at 18:32
$begingroup$
@ceilingcat Doesn't work for f(6,1)
$endgroup$
– cleblanc
Jan 16 at 18:32
|
show 2 more comments
$begingroup$
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.
$endgroup$
1
$begingroup$
Since it is not very clearly specified, can you not assume the input is a list of integers, thus eliminating the initial|
?
$endgroup$
– Wisław
Jan 16 at 17:22
$begingroup$
@Wisław Good point, I updated my answer. Thanks!
$endgroup$
– Cowabunghole
Jan 16 at 17:28
$begingroup$
I found a 11 bytes alternative:OI`αª5¢IË~Ā
. Input is a list of integers.
$endgroup$
– Wisław
Jan 16 at 17:54
1
$begingroup$
OIÆÄ)5QIËM
is 10.
$endgroup$
– Magic Octopus Urn
Jan 16 at 18:35
1
$begingroup$
@MagicOctopusUrn I'm not sure exactly what the rules are but I think your solution is different enough from mine to submit your own answer, no? Also, unrelated but I've seen your username on this site for a long time but only after typing it out did I realize that it's "Urn", not "Um" :)
$endgroup$
– Cowabunghole
Jan 16 at 18:43
|
show 2 more comments
$begingroup$
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.
$endgroup$
1
$begingroup$
Since it is not very clearly specified, can you not assume the input is a list of integers, thus eliminating the initial|
?
$endgroup$
– Wisław
Jan 16 at 17:22
$begingroup$
@Wisław Good point, I updated my answer. Thanks!
$endgroup$
– Cowabunghole
Jan 16 at 17:28
$begingroup$
I found a 11 bytes alternative:OI`αª5¢IË~Ā
. Input is a list of integers.
$endgroup$
– Wisław
Jan 16 at 17:54
1
$begingroup$
OIÆÄ)5QIËM
is 10.
$endgroup$
– Magic Octopus Urn
Jan 16 at 18:35
1
$begingroup$
@MagicOctopusUrn I'm not sure exactly what the rules are but I think your solution is different enough from mine to submit your own answer, no? Also, unrelated but I've seen your username on this site for a long time but only after typing it out did I realize that it's "Urn", not "Um" :)
$endgroup$
– Cowabunghole
Jan 16 at 18:43
|
show 2 more comments
$begingroup$
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.
$endgroup$
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.
edited Jan 16 at 17:52
answered Jan 16 at 17:02


CowabungholeCowabunghole
1,095420
1,095420
1
$begingroup$
Since it is not very clearly specified, can you not assume the input is a list of integers, thus eliminating the initial|
?
$endgroup$
– Wisław
Jan 16 at 17:22
$begingroup$
@Wisław Good point, I updated my answer. Thanks!
$endgroup$
– Cowabunghole
Jan 16 at 17:28
$begingroup$
I found a 11 bytes alternative:OI`αª5¢IË~Ā
. Input is a list of integers.
$endgroup$
– Wisław
Jan 16 at 17:54
1
$begingroup$
OIÆÄ)5QIËM
is 10.
$endgroup$
– Magic Octopus Urn
Jan 16 at 18:35
1
$begingroup$
@MagicOctopusUrn I'm not sure exactly what the rules are but I think your solution is different enough from mine to submit your own answer, no? Also, unrelated but I've seen your username on this site for a long time but only after typing it out did I realize that it's "Urn", not "Um" :)
$endgroup$
– Cowabunghole
Jan 16 at 18:43
|
show 2 more comments
1
$begingroup$
Since it is not very clearly specified, can you not assume the input is a list of integers, thus eliminating the initial|
?
$endgroup$
– Wisław
Jan 16 at 17:22
$begingroup$
@Wisław Good point, I updated my answer. Thanks!
$endgroup$
– Cowabunghole
Jan 16 at 17:28
$begingroup$
I found a 11 bytes alternative:OI`αª5¢IË~Ā
. Input is a list of integers.
$endgroup$
– Wisław
Jan 16 at 17:54
1
$begingroup$
OIÆÄ)5QIËM
is 10.
$endgroup$
– Magic Octopus Urn
Jan 16 at 18:35
1
$begingroup$
@MagicOctopusUrn I'm not sure exactly what the rules are but I think your solution is different enough from mine to submit your own answer, no? Also, unrelated but I've seen your username on this site for a long time but only after typing it out did I realize that it's "Urn", not "Um" :)
$endgroup$
– Cowabunghole
Jan 16 at 18:43
1
1
$begingroup$
Since it is not very clearly specified, can you not assume the input is a list of integers, thus eliminating the initial
|
?$endgroup$
– Wisław
Jan 16 at 17:22
$begingroup$
Since it is not very clearly specified, can you not assume the input is a list of integers, thus eliminating the initial
|
?$endgroup$
– Wisław
Jan 16 at 17:22
$begingroup$
@Wisław Good point, I updated my answer. Thanks!
$endgroup$
– Cowabunghole
Jan 16 at 17:28
$begingroup$
@Wisław Good point, I updated my answer. Thanks!
$endgroup$
– Cowabunghole
Jan 16 at 17:28
$begingroup$
I found a 11 bytes alternative:
OI`αª5¢IË~Ā
. Input is a list of integers.$endgroup$
– Wisław
Jan 16 at 17:54
$begingroup$
I found a 11 bytes alternative:
OI`αª5¢IË~Ā
. Input is a list of integers.$endgroup$
– Wisław
Jan 16 at 17:54
1
1
$begingroup$
OIÆÄ)5QIËM
is 10.$endgroup$
– Magic Octopus Urn
Jan 16 at 18:35
$begingroup$
OIÆÄ)5QIËM
is 10.$endgroup$
– Magic Octopus Urn
Jan 16 at 18:35
1
1
$begingroup$
@MagicOctopusUrn I'm not sure exactly what the rules are but I think your solution is different enough from mine to submit your own answer, no? Also, unrelated but I've seen your username on this site for a long time but only after typing it out did I realize that it's "Urn", not "Um" :)
$endgroup$
– Cowabunghole
Jan 16 at 18:43
$begingroup$
@MagicOctopusUrn I'm not sure exactly what the rules are but I think your solution is different enough from mine to submit your own answer, no? Also, unrelated but I've seen your username on this site for a long time but only after typing it out did I realize that it's "Urn", not "Um" :)
$endgroup$
– Cowabunghole
Jan 16 at 18:43
|
show 2 more comments
$begingroup$
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.
$endgroup$
1
$begingroup$
This will unfortunately return true if the sum is0
such as for[5, -5]
$endgroup$
– Emigna
Jan 16 at 20:28
1
$begingroup$
Your other 10-byte solution that you left as a comment (OIÆÄ‚5QIËM
) is correct for[5,-5]
.
$endgroup$
– Kevin Cruijssen
Jan 17 at 9:31
$begingroup$
Another 10-byte solution that I came up with isOsÆÄ‚5åsË~
. Almost identical to yours it seems. Try it online!
$endgroup$
– Wisław
Jan 17 at 10:54
add a comment |
$begingroup$
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.
$endgroup$
1
$begingroup$
This will unfortunately return true if the sum is0
such as for[5, -5]
$endgroup$
– Emigna
Jan 16 at 20:28
1
$begingroup$
Your other 10-byte solution that you left as a comment (OIÆÄ‚5QIËM
) is correct for[5,-5]
.
$endgroup$
– Kevin Cruijssen
Jan 17 at 9:31
$begingroup$
Another 10-byte solution that I came up with isOsÆÄ‚5åsË~
. Almost identical to yours it seems. Try it online!
$endgroup$
– Wisław
Jan 17 at 10:54
add a comment |
$begingroup$
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.
$endgroup$
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.
answered Jan 16 at 18:23


Magic Octopus UrnMagic Octopus Urn
12.7k444126
12.7k444126
1
$begingroup$
This will unfortunately return true if the sum is0
such as for[5, -5]
$endgroup$
– Emigna
Jan 16 at 20:28
1
$begingroup$
Your other 10-byte solution that you left as a comment (OIÆÄ‚5QIËM
) is correct for[5,-5]
.
$endgroup$
– Kevin Cruijssen
Jan 17 at 9:31
$begingroup$
Another 10-byte solution that I came up with isOsÆÄ‚5åsË~
. Almost identical to yours it seems. Try it online!
$endgroup$
– Wisław
Jan 17 at 10:54
add a comment |
1
$begingroup$
This will unfortunately return true if the sum is0
such as for[5, -5]
$endgroup$
– Emigna
Jan 16 at 20:28
1
$begingroup$
Your other 10-byte solution that you left as a comment (OIÆÄ‚5QIËM
) is correct for[5,-5]
.
$endgroup$
– Kevin Cruijssen
Jan 17 at 9:31
$begingroup$
Another 10-byte solution that I came up with isOsÆÄ‚5åsË~
. Almost identical to yours it seems. Try it online!
$endgroup$
– Wisław
Jan 17 at 10:54
1
1
$begingroup$
This will unfortunately return true if the sum is
0
such as for [5, -5]
$endgroup$
– Emigna
Jan 16 at 20:28
$begingroup$
This will unfortunately return true if the sum is
0
such as for [5, -5]
$endgroup$
– Emigna
Jan 16 at 20:28
1
1
$begingroup$
Your other 10-byte solution that you left as a comment (
OIÆÄ‚5QIËM
) is correct for [5,-5]
.$endgroup$
– Kevin Cruijssen
Jan 17 at 9:31
$begingroup$
Your other 10-byte solution that you left as a comment (
OIÆÄ‚5QIËM
) is correct for [5,-5]
.$endgroup$
– Kevin Cruijssen
Jan 17 at 9:31
$begingroup$
Another 10-byte solution that I came up with is
OsÆÄ‚5åsË~
. Almost identical to yours it seems. Try it online!$endgroup$
– Wisław
Jan 17 at 10:54
$begingroup$
Another 10-byte solution that I came up with is
OsÆÄ‚5åsË~
. Almost identical to yours it seems. Try it online!$endgroup$
– Wisław
Jan 17 at 10:54
add a comment |
$begingroup$
Ruby, 34 Bytes
->(a,b){[a+5,a-5,5-a,a].include?b}
Online Eval
- Thanks @ASCII-Only
$endgroup$
$begingroup$
do you check if they're equal though...
$endgroup$
– ASCII-only
Jan 20 at 12:20
$begingroup$
Oops, forgot to add that check. Thanks @ASCII-only for pointing out the mistake.
$endgroup$
– Jatin Dhankhar
Jan 20 at 12:23
1
$begingroup$
i'd be nice if you could link to this
$endgroup$
– ASCII-only
Jan 21 at 2:57
$begingroup$
this might be valid? not completely sure though, you might wanna check with someone else
$endgroup$
– ASCII-only
Jan 28 at 4:45
$begingroup$
This will work but it requires.nil?
check to give output in the required format.->(a,b){[a+5,a-5,5-a,a].index(b).nil?}
, this is longer than the current one.
$endgroup$
– Jatin Dhankhar
Jan 28 at 5:04
|
show 1 more comment
$begingroup$
Ruby, 34 Bytes
->(a,b){[a+5,a-5,5-a,a].include?b}
Online Eval
- Thanks @ASCII-Only
$endgroup$
$begingroup$
do you check if they're equal though...
$endgroup$
– ASCII-only
Jan 20 at 12:20
$begingroup$
Oops, forgot to add that check. Thanks @ASCII-only for pointing out the mistake.
$endgroup$
– Jatin Dhankhar
Jan 20 at 12:23
1
$begingroup$
i'd be nice if you could link to this
$endgroup$
– ASCII-only
Jan 21 at 2:57
$begingroup$
this might be valid? not completely sure though, you might wanna check with someone else
$endgroup$
– ASCII-only
Jan 28 at 4:45
$begingroup$
This will work but it requires.nil?
check to give output in the required format.->(a,b){[a+5,a-5,5-a,a].index(b).nil?}
, this is longer than the current one.
$endgroup$
– Jatin Dhankhar
Jan 28 at 5:04
|
show 1 more comment
$begingroup$
Ruby, 34 Bytes
->(a,b){[a+5,a-5,5-a,a].include?b}
Online Eval
- Thanks @ASCII-Only
$endgroup$
Ruby, 34 Bytes
->(a,b){[a+5,a-5,5-a,a].include?b}
Online Eval
- Thanks @ASCII-Only
edited Jan 24 at 10:58
answered Jan 20 at 11:52


Jatin DhankharJatin Dhankhar
1316
1316
$begingroup$
do you check if they're equal though...
$endgroup$
– ASCII-only
Jan 20 at 12:20
$begingroup$
Oops, forgot to add that check. Thanks @ASCII-only for pointing out the mistake.
$endgroup$
– Jatin Dhankhar
Jan 20 at 12:23
1
$begingroup$
i'd be nice if you could link to this
$endgroup$
– ASCII-only
Jan 21 at 2:57
$begingroup$
this might be valid? not completely sure though, you might wanna check with someone else
$endgroup$
– ASCII-only
Jan 28 at 4:45
$begingroup$
This will work but it requires.nil?
check to give output in the required format.->(a,b){[a+5,a-5,5-a,a].index(b).nil?}
, this is longer than the current one.
$endgroup$
– Jatin Dhankhar
Jan 28 at 5:04
|
show 1 more comment
$begingroup$
do you check if they're equal though...
$endgroup$
– ASCII-only
Jan 20 at 12:20
$begingroup$
Oops, forgot to add that check. Thanks @ASCII-only for pointing out the mistake.
$endgroup$
– Jatin Dhankhar
Jan 20 at 12:23
1
$begingroup$
i'd be nice if you could link to this
$endgroup$
– ASCII-only
Jan 21 at 2:57
$begingroup$
this might be valid? not completely sure though, you might wanna check with someone else
$endgroup$
– ASCII-only
Jan 28 at 4:45
$begingroup$
This will work but it requires.nil?
check to give output in the required format.->(a,b){[a+5,a-5,5-a,a].index(b).nil?}
, this is longer than the current one.
$endgroup$
– Jatin Dhankhar
Jan 28 at 5:04
$begingroup$
do you check if they're equal though...
$endgroup$
– ASCII-only
Jan 20 at 12:20
$begingroup$
do you check if they're equal though...
$endgroup$
– ASCII-only
Jan 20 at 12:20
$begingroup$
Oops, forgot to add that check. Thanks @ASCII-only for pointing out the mistake.
$endgroup$
– Jatin Dhankhar
Jan 20 at 12:23
$begingroup$
Oops, forgot to add that check. Thanks @ASCII-only for pointing out the mistake.
$endgroup$
– Jatin Dhankhar
Jan 20 at 12:23
1
1
$begingroup$
i'd be nice if you could link to this
$endgroup$
– ASCII-only
Jan 21 at 2:57
$begingroup$
i'd be nice if you could link to this
$endgroup$
– ASCII-only
Jan 21 at 2:57
$begingroup$
this might be valid? not completely sure though, you might wanna check with someone else
$endgroup$
– ASCII-only
Jan 28 at 4:45
$begingroup$
this might be valid? not completely sure though, you might wanna check with someone else
$endgroup$
– ASCII-only
Jan 28 at 4:45
$begingroup$
This will work but it requires
.nil?
check to give output in the required format. ->(a,b){[a+5,a-5,5-a,a].index(b).nil?}
, this is longer than the current one.$endgroup$
– Jatin Dhankhar
Jan 28 at 5:04
$begingroup$
This will work but it requires
.nil?
check to give output in the required format. ->(a,b){[a+5,a-5,5-a,a].index(b).nil?}
, this is longer than the current one.$endgroup$
– Jatin Dhankhar
Jan 28 at 5:04
|
show 1 more comment
$begingroup$
Tcl, 53 bytes
proc P a b {expr abs($a-$b)==5|$a==$b|abs($a+$b)==5}
Try it online!
$endgroup$
add a comment |
$begingroup$
Tcl, 53 bytes
proc P a b {expr abs($a-$b)==5|$a==$b|abs($a+$b)==5}
Try it online!
$endgroup$
add a comment |
$begingroup$
Tcl, 53 bytes
proc P a b {expr abs($a-$b)==5|$a==$b|abs($a+$b)==5}
Try it online!
$endgroup$
Tcl, 53 bytes
proc P a b {expr abs($a-$b)==5|$a==$b|abs($a+$b)==5}
Try it online!
edited Jan 16 at 17:06
answered Jan 16 at 16:49
sergiolsergiol
2,5251925
2,5251925
add a comment |
add a comment |
$begingroup$
Japt, 14 13 bytes
¥VªaU ¥5ª5¥Nx
Try it online!
$endgroup$
add a comment |
$begingroup$
Japt, 14 13 bytes
¥VªaU ¥5ª5¥Nx
Try it online!
$endgroup$
add a comment |
$begingroup$
Japt, 14 13 bytes
¥VªaU ¥5ª5¥Nx
Try it online!
$endgroup$
Japt, 14 13 bytes
¥VªaU ¥5ª5¥Nx
Try it online!
edited Jan 16 at 17:51
answered Jan 16 at 16:32
OliverOliver
4,9551832
4,9551832
add a comment |
add a comment |
$begingroup$
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.
$endgroup$
add a comment |
$begingroup$
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.
$endgroup$
add a comment |
$begingroup$
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.
$endgroup$
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.
answered Jan 16 at 18:14
NeilNeil
80.9k744178
80.9k744178
add a comment |
add a comment |
$begingroup$
Charcoal, 18 bytes
Nθ¿№⟦θ⁺⁵θ⁻⁵θ⁻θ⁵⟧N1
Try it online! Link is to verbose version of code. Port of @ArBo's Python 2 solution.
$endgroup$
add a comment |
$begingroup$
Charcoal, 18 bytes
Nθ¿№⟦θ⁺⁵θ⁻⁵θ⁻θ⁵⟧N1
Try it online! Link is to verbose version of code. Port of @ArBo's Python 2 solution.
$endgroup$
add a comment |
$begingroup$
Charcoal, 18 bytes
Nθ¿№⟦θ⁺⁵θ⁻⁵θ⁻θ⁵⟧N1
Try it online! Link is to verbose version of code. Port of @ArBo's Python 2 solution.
$endgroup$
Charcoal, 18 bytes
Nθ¿№⟦θ⁺⁵θ⁻⁵θ⁻θ⁵⟧N1
Try it online! Link is to verbose version of code. Port of @ArBo's Python 2 solution.
answered Jan 16 at 18:30
NeilNeil
80.9k744178
80.9k744178
add a comment |
add a comment |
$begingroup$
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
$endgroup$
$begingroup$
Fails for[-5,5]
(should be falsey)
$endgroup$
– Kevin Cruijssen
Jan 17 at 9:26
$begingroup$
Thanks, @KevinCruijssen. Rolled back to the previous version.
$endgroup$
– Shaggy
Jan 17 at 9:50
add a comment |
$begingroup$
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
$endgroup$
$begingroup$
Fails for[-5,5]
(should be falsey)
$endgroup$
– Kevin Cruijssen
Jan 17 at 9:26
$begingroup$
Thanks, @KevinCruijssen. Rolled back to the previous version.
$endgroup$
– Shaggy
Jan 17 at 9:50
add a comment |
$begingroup$
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
$endgroup$
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
edited Jan 17 at 9:49
answered Jan 16 at 16:52


ShaggyShaggy
20.1k21667
20.1k21667
$begingroup$
Fails for[-5,5]
(should be falsey)
$endgroup$
– Kevin Cruijssen
Jan 17 at 9:26
$begingroup$
Thanks, @KevinCruijssen. Rolled back to the previous version.
$endgroup$
– Shaggy
Jan 17 at 9:50
add a comment |
$begingroup$
Fails for[-5,5]
(should be falsey)
$endgroup$
– Kevin Cruijssen
Jan 17 at 9:26
$begingroup$
Thanks, @KevinCruijssen. Rolled back to the previous version.
$endgroup$
– Shaggy
Jan 17 at 9:50
$begingroup$
Fails for
[-5,5]
(should be falsey)$endgroup$
– Kevin Cruijssen
Jan 17 at 9:26
$begingroup$
Fails for
[-5,5]
(should be falsey)$endgroup$
– Kevin Cruijssen
Jan 17 at 9:26
$begingroup$
Thanks, @KevinCruijssen. Rolled back to the previous version.
$endgroup$
– Shaggy
Jan 17 at 9:50
$begingroup$
Thanks, @KevinCruijssen. Rolled back to the previous version.
$endgroup$
– Shaggy
Jan 17 at 9:50
add a comment |
$begingroup$
Common Lisp, 48 bytes
(lambda(a b)(find 5(list(abs(- b a))a(+ a b)b)))
$endgroup$
add a comment |
$begingroup$
Common Lisp, 48 bytes
(lambda(a b)(find 5(list(abs(- b a))a(+ a b)b)))
$endgroup$
add a comment |
$begingroup$
Common Lisp, 48 bytes
(lambda(a b)(find 5(list(abs(- b a))a(+ a b)b)))
$endgroup$
Common Lisp, 48 bytes
(lambda(a b)(find 5(list(abs(- b a))a(+ a b)b)))
answered Jan 17 at 12:19


coredumpcoredump
5,7071641
5,7071641
add a comment |
add a comment |
$begingroup$
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
$endgroup$
add a comment |
$begingroup$
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
$endgroup$
add a comment |
$begingroup$
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
$endgroup$
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
answered Feb 16 at 4:22


DLoscDLosc
19.3k33889
19.3k33889
add a comment |
add a comment |
$begingroup$
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$
$endgroup$
add a comment |
$begingroup$
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$
$endgroup$
add a comment |
$begingroup$
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$
$endgroup$
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$
answered Jan 17 at 0:41
NeilNeil
80.9k744178
80.9k744178
add a comment |
add a comment |
1 2
next
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f178792%2fequal-sum-or-difference%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
9
$begingroup$
welcome to PPCG! This is a good first challenge -- the challenge is clearly defined, it has ample test cases, and uses our default I/O! If you stick around for a while and keep thinking up interesting challenges, I would recommend using The Sandbox to get feedback before posting them to this site. I hope you enjoy the time you spend here!
$endgroup$
– Giuseppe
Jan 16 at 16:22