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 difference is 5.
Example test cases:
4 1 => True
10 10 => True
1 3 => False
6 2 => False
1 6 => True
-256 -251 => True
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
code-golf decision-problem
New contributor
$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 difference is 5.
Example test cases:
4 1 => True
10 10 => True
1 3 => False
6 2 => False
1 6 => True
-256 -251 => True
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
code-golf decision-problem
New contributor
$endgroup$
$begingroup$
Just for info, you can reduce your 56 by 9 by replacingx=input();y=input()
withx,y=input()
and giving the input as 2 integers separated by a comma.
$endgroup$
– ElPedro
47 mins ago
1
$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
33 mins ago
add a comment |
$begingroup$
Write shortest possible code that will return true if the two given integer values are equal or their sum or difference is 5.
Example test cases:
4 1 => True
10 10 => True
1 3 => False
6 2 => False
1 6 => True
-256 -251 => True
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
code-golf decision-problem
New contributor
$endgroup$
Write shortest possible code that will return true if the two given integer values are equal or their sum or difference is 5.
Example test cases:
4 1 => True
10 10 => True
1 3 => False
6 2 => False
1 6 => True
-256 -251 => True
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
code-golf decision-problem
code-golf decision-problem
New contributor
New contributor
edited 32 mins ago
Sok
3,607723
3,607723
New contributor
asked 57 mins ago
Vikrant BiswasVikrant Biswas
363
363
New contributor
New contributor
$begingroup$
Just for info, you can reduce your 56 by 9 by replacingx=input();y=input()
withx,y=input()
and giving the input as 2 integers separated by a comma.
$endgroup$
– ElPedro
47 mins ago
1
$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
33 mins ago
add a comment |
$begingroup$
Just for info, you can reduce your 56 by 9 by replacingx=input();y=input()
withx,y=input()
and giving the input as 2 integers separated by a comma.
$endgroup$
– ElPedro
47 mins ago
1
$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
33 mins ago
$begingroup$
Just for info, you can reduce your 56 by 9 by replacing
x=input();y=input()
with x,y=input()
and giving the input as 2 integers separated by a comma.$endgroup$
– ElPedro
47 mins ago
$begingroup$
Just for info, you can reduce your 56 by 9 by replacing
x=input();y=input()
with x,y=input()
and giving the input as 2 integers separated by a comma.$endgroup$
– ElPedro
47 mins ago
1
1
$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
33 mins ago
$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
33 mins ago
add a comment |
15 Answers
15
active
oldest
votes
$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$
add a comment |
$begingroup$
Python 2, 40 bytes
lambda a,b:a+b==5 or abs(a-b)==5 or 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
43 mins ago
1
$begingroup$
Actually, the TIO link could be 38 bytes
$endgroup$
– DJMcMayhem♦
40 mins ago
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, 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$
1
$begingroup$
lambda a,b:a in(b,5-b,b-5,b+5)
$endgroup$
– alephalpha
4 mins ago
add a comment |
$begingroup$
PowerShell, 48 bytes
param($a,$b)5-in($x=$b-$a),($a-$b),($a+$b)-or!$x
Try it online!
Takes input $a
and $b
. Checks if 5
is -in
the group $b-$a
, $a-$b
, or $a+$b
, stores the first into $x
, and -or
s the -in
check with !$x
to check equality.
$endgroup$
add a comment |
$begingroup$
Japt, 14 bytes
r¥ ª[Ux Ura]ø5
Try it online!
$endgroup$
add a comment |
$begingroup$
Japt, 12 bytes
¶Vª(U-V a ¶5
Very lazy, simply checks equal or absolute difference.
Try it online!
$endgroup$
2
$begingroup$
Welcome back! Unfortunately, this isn't checking for sum == 5
$endgroup$
– Oliver
4 mins ago
add a comment |
$begingroup$
C (gcc), 41 36 bytes
f(a,b){a=5==abs(a-b)||a+b==5||a==b;}
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 26 bytes
!{#,5-#,#-5,#+5}~FreeQ~#2&
Try it online!
$endgroup$
add a comment |
$begingroup$
Scala, 45 bytes
def f(a:Int,b:Int)=a+b==5||(a-b).abs==5||a==b
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (.NET Core), 43, 48, 47 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!
(a,b)=>{return(a-b)*(a-b)==25|a==b|a+b==5?1:0;}
Try it online!
$endgroup$
$begingroup$
Bah. Trying to avoid System.Math. Back to it! Thanks for pointing that out :D
$endgroup$
– Destroigo
13 mins ago
add a comment |
$begingroup$
Japt, 13 12 bytes
x ¥5|50sèUra
Try it or run all test cases
$endgroup$
add a comment |
$begingroup$
J, 12 bytes
1#.=+5=|@-,+
Try it online!
Explanation
This is equivalent to:
1 #. = + 5 = |@- , +
This can be divided into the following fork chain:
(1 #. (= + (5 = (|@- , +))))
Or, visualized using 5!:4<'f'
:
┌─ 1
├─ #.
──┤ ┌─ =
│ ├─ +
└────┤ ┌─ 5
│ ├─ =
└───┤ ┌─ |
│ ┌─ @ ─┴─ -
└───┼─ ,
└─ +
Annotated:
┌─ 1 noun 1
├─ #. base conversion (summation - any?)
──┤ ┌─ = equality
│ ├─ + added to (boolean or)
└────┤ ┌─ 5 noun 5
│ ├─ = is equal to
└───┤ ┌─ | absolute value |
│ ┌─ @ ─┴─ - (of) subtraction |
└───┼─ , paired with |
└─ + subtraction | any of these?
$endgroup$
add a comment |
$begingroup$
Dyalog APL, 9 bytes
=∨5∊+,∘|-
Try it online!
$endgroup$
add a comment |
$begingroup$
Tcl, 58 bytes
proc P a b {expr [set m abs($a-$b)]==5|!$m|abs($a+$b)==5}
Try it online!
$endgroup$
add a comment |
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
});
}
});
Vikrant Biswas is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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
15 Answers
15
active
oldest
votes
15 Answers
15
active
oldest
votes
active
oldest
votes
active
oldest
votes
$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$
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$
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 35 mins ago
answered 48 mins ago
ArnauldArnauld
73.2k689307
73.2k689307
add a comment |
add a comment |
$begingroup$
Python 2, 40 bytes
lambda a,b:a+b==5 or abs(a-b)==5 or 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
43 mins ago
1
$begingroup$
Actually, the TIO link could be 38 bytes
$endgroup$
– DJMcMayhem♦
40 mins ago
add a comment |
$begingroup$
Python 2, 40 bytes
lambda a,b:a+b==5 or abs(a-b)==5 or 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
43 mins ago
1
$begingroup$
Actually, the TIO link could be 38 bytes
$endgroup$
– DJMcMayhem♦
40 mins ago
add a comment |
$begingroup$
Python 2, 40 bytes
lambda a,b:a+b==5 or abs(a-b)==5 or a==b
Try it online!
$endgroup$
Python 2, 40 bytes
lambda a,b:a+b==5 or abs(a-b)==5 or a==b
Try it online!
answered 46 mins ago
fəˈnɛtɪkfəˈnɛtɪk
3,6331637
3,6331637
$begingroup$
Your TIO is actually 42 bytes but you can fix it by deleting the spaces between the5
s and theor
s
$endgroup$
– ElPedro
43 mins ago
1
$begingroup$
Actually, the TIO link could be 38 bytes
$endgroup$
– DJMcMayhem♦
40 mins ago
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
43 mins ago
1
$begingroup$
Actually, the TIO link could be 38 bytes
$endgroup$
– DJMcMayhem♦
40 mins ago
$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
43 mins ago
$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
43 mins ago
1
1
$begingroup$
Actually, the TIO link could be 38 bytes
$endgroup$
– DJMcMayhem♦
40 mins ago
$begingroup$
Actually, the TIO link could be 38 bytes
$endgroup$
– DJMcMayhem♦
40 mins ago
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 32 mins ago
Dennis♦Dennis
187k32297736
187k32297736
add a comment |
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$
1
$begingroup$
lambda a,b:a in(b,5-b,b-5,b+5)
$endgroup$
– alephalpha
4 mins ago
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$
1
$begingroup$
lambda a,b:a in(b,5-b,b-5,b+5)
$endgroup$
– alephalpha
4 mins ago
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 50 secs ago
answered 9 mins ago
ArBoArBo
1214
1214
1
$begingroup$
lambda a,b:a in(b,5-b,b-5,b+5)
$endgroup$
– alephalpha
4 mins ago
add a comment |
1
$begingroup$
lambda a,b:a in(b,5-b,b-5,b+5)
$endgroup$
– alephalpha
4 mins ago
1
1
$begingroup$
lambda a,b:a in(b,5-b,b-5,b+5)
$endgroup$
– alephalpha
4 mins ago
$begingroup$
lambda a,b:a in(b,5-b,b-5,b+5)
$endgroup$
– alephalpha
4 mins ago
add a comment |
$begingroup$
PowerShell, 48 bytes
param($a,$b)5-in($x=$b-$a),($a-$b),($a+$b)-or!$x
Try it online!
Takes input $a
and $b
. Checks if 5
is -in
the group $b-$a
, $a-$b
, or $a+$b
, stores the first into $x
, and -or
s the -in
check with !$x
to check equality.
$endgroup$
add a comment |
$begingroup$
PowerShell, 48 bytes
param($a,$b)5-in($x=$b-$a),($a-$b),($a+$b)-or!$x
Try it online!
Takes input $a
and $b
. Checks if 5
is -in
the group $b-$a
, $a-$b
, or $a+$b
, stores the first into $x
, and -or
s the -in
check with !$x
to check equality.
$endgroup$
add a comment |
$begingroup$
PowerShell, 48 bytes
param($a,$b)5-in($x=$b-$a),($a-$b),($a+$b)-or!$x
Try it online!
Takes input $a
and $b
. Checks if 5
is -in
the group $b-$a
, $a-$b
, or $a+$b
, stores the first into $x
, and -or
s the -in
check with !$x
to check equality.
$endgroup$
PowerShell, 48 bytes
param($a,$b)5-in($x=$b-$a),($a-$b),($a+$b)-or!$x
Try it online!
Takes input $a
and $b
. Checks if 5
is -in
the group $b-$a
, $a-$b
, or $a+$b
, stores the first into $x
, and -or
s the -in
check with !$x
to check equality.
answered 26 mins ago
AdmBorkBorkAdmBorkBork
26.5k364229
26.5k364229
add a comment |
add a comment |
$begingroup$
Japt, 14 bytes
r¥ ª[Ux Ura]ø5
Try it online!
$endgroup$
add a comment |
$begingroup$
Japt, 14 bytes
r¥ ª[Ux Ura]ø5
Try it online!
$endgroup$
add a comment |
$begingroup$
Japt, 14 bytes
r¥ ª[Ux Ura]ø5
Try it online!
$endgroup$
Japt, 14 bytes
r¥ ª[Ux Ura]ø5
Try it online!
answered 22 mins ago
OliverOliver
4,7501831
4,7501831
add a comment |
add a comment |
$begingroup$
Japt, 12 bytes
¶Vª(U-V a ¶5
Very lazy, simply checks equal or absolute difference.
Try it online!
$endgroup$
2
$begingroup$
Welcome back! Unfortunately, this isn't checking for sum == 5
$endgroup$
– Oliver
4 mins ago
add a comment |
$begingroup$
Japt, 12 bytes
¶Vª(U-V a ¶5
Very lazy, simply checks equal or absolute difference.
Try it online!
$endgroup$
2
$begingroup$
Welcome back! Unfortunately, this isn't checking for sum == 5
$endgroup$
– Oliver
4 mins ago
add a comment |
$begingroup$
Japt, 12 bytes
¶Vª(U-V a ¶5
Very lazy, simply checks equal or absolute difference.
Try it online!
$endgroup$
Japt, 12 bytes
¶Vª(U-V a ¶5
Very lazy, simply checks equal or absolute difference.
Try it online!
answered 19 mins ago
NitNit
1,92511419
1,92511419
2
$begingroup$
Welcome back! Unfortunately, this isn't checking for sum == 5
$endgroup$
– Oliver
4 mins ago
add a comment |
2
$begingroup$
Welcome back! Unfortunately, this isn't checking for sum == 5
$endgroup$
– Oliver
4 mins ago
2
2
$begingroup$
Welcome back! Unfortunately, this isn't checking for sum == 5
$endgroup$
– Oliver
4 mins ago
$begingroup$
Welcome back! Unfortunately, this isn't checking for sum == 5
$endgroup$
– Oliver
4 mins ago
add a comment |
$begingroup$
C (gcc), 41 36 bytes
f(a,b){a=5==abs(a-b)||a+b==5||a==b;}
Try it online!
$endgroup$
add a comment |
$begingroup$
C (gcc), 41 36 bytes
f(a,b){a=5==abs(a-b)||a+b==5||a==b;}
Try it online!
$endgroup$
add a comment |
$begingroup$
C (gcc), 41 36 bytes
f(a,b){a=5==abs(a-b)||a+b==5||a==b;}
Try it online!
$endgroup$
C (gcc), 41 36 bytes
f(a,b){a=5==abs(a-b)||a+b==5||a==b;}
Try it online!
answered 18 mins ago
cleblanccleblanc
3,180316
3,180316
add a comment |
add a comment |
$begingroup$
Wolfram Language (Mathematica), 26 bytes
!{#,5-#,#-5,#+5}~FreeQ~#2&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 26 bytes
!{#,5-#,#-5,#+5}~FreeQ~#2&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 26 bytes
!{#,5-#,#-5,#+5}~FreeQ~#2&
Try it online!
$endgroup$
Wolfram Language (Mathematica), 26 bytes
!{#,5-#,#-5,#+5}~FreeQ~#2&
Try it online!
answered 5 mins ago
alephalphaalephalpha
21.2k32991
21.2k32991
add a comment |
add a comment |
$begingroup$
Scala, 45 bytes
def f(a:Int,b:Int)=a+b==5||(a-b).abs==5||a==b
Try it online!
$endgroup$
add a comment |
$begingroup$
Scala, 45 bytes
def f(a:Int,b:Int)=a+b==5||(a-b).abs==5||a==b
Try it online!
$endgroup$
add a comment |
$begingroup$
Scala, 45 bytes
def f(a:Int,b:Int)=a+b==5||(a-b).abs==5||a==b
Try it online!
$endgroup$
Scala, 45 bytes
def f(a:Int,b:Int)=a+b==5||(a-b).abs==5||a==b
Try it online!
answered 4 mins ago
Xavier GuihotXavier Guihot
1937
1937
add a comment |
add a comment |
$begingroup$
C# (.NET Core), 43, 48, 47 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!
(a,b)=>{return(a-b)*(a-b)==25|a==b|a+b==5?1:0;}
Try it online!
$endgroup$
$begingroup$
Bah. Trying to avoid System.Math. Back to it! Thanks for pointing that out :D
$endgroup$
– Destroigo
13 mins ago
add a comment |
$begingroup$
C# (.NET Core), 43, 48, 47 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!
(a,b)=>{return(a-b)*(a-b)==25|a==b|a+b==5?1:0;}
Try it online!
$endgroup$
$begingroup$
Bah. Trying to avoid System.Math. Back to it! Thanks for pointing that out :D
$endgroup$
– Destroigo
13 mins ago
add a comment |
$begingroup$
C# (.NET Core), 43, 48, 47 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!
(a,b)=>{return(a-b)*(a-b)==25|a==b|a+b==5?1:0;}
Try it online!
$endgroup$
C# (.NET Core), 43, 48, 47 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!
(a,b)=>{return(a-b)*(a-b)==25|a==b|a+b==5?1:0;}
Try it online!
edited 3 mins ago
answered 23 mins ago
DestroigoDestroigo
1515
1515
$begingroup$
Bah. Trying to avoid System.Math. Back to it! Thanks for pointing that out :D
$endgroup$
– Destroigo
13 mins ago
add a comment |
$begingroup$
Bah. Trying to avoid System.Math. Back to it! Thanks for pointing that out :D
$endgroup$
– Destroigo
13 mins ago
$begingroup$
Bah. Trying to avoid System.Math. Back to it! Thanks for pointing that out :D
$endgroup$
– Destroigo
13 mins ago
$begingroup$
Bah. Trying to avoid System.Math. Back to it! Thanks for pointing that out :D
$endgroup$
– Destroigo
13 mins ago
add a comment |
$begingroup$
Japt, 13 12 bytes
x ¥5|50sèUra
Try it or run all test cases
$endgroup$
add a comment |
$begingroup$
Japt, 13 12 bytes
x ¥5|50sèUra
Try it or run all test cases
$endgroup$
add a comment |
$begingroup$
Japt, 13 12 bytes
x ¥5|50sèUra
Try it or run all test cases
$endgroup$
Japt, 13 12 bytes
x ¥5|50sèUra
Try it or run all test cases
answered 2 mins ago
ShaggyShaggy
19.2k21666
19.2k21666
add a comment |
add a comment |
$begingroup$
J, 12 bytes
1#.=+5=|@-,+
Try it online!
Explanation
This is equivalent to:
1 #. = + 5 = |@- , +
This can be divided into the following fork chain:
(1 #. (= + (5 = (|@- , +))))
Or, visualized using 5!:4<'f'
:
┌─ 1
├─ #.
──┤ ┌─ =
│ ├─ +
└────┤ ┌─ 5
│ ├─ =
└───┤ ┌─ |
│ ┌─ @ ─┴─ -
└───┼─ ,
└─ +
Annotated:
┌─ 1 noun 1
├─ #. base conversion (summation - any?)
──┤ ┌─ = equality
│ ├─ + added to (boolean or)
└────┤ ┌─ 5 noun 5
│ ├─ = is equal to
└───┤ ┌─ | absolute value |
│ ┌─ @ ─┴─ - (of) subtraction |
└───┼─ , paired with |
└─ + subtraction | any of these?
$endgroup$
add a comment |
$begingroup$
J, 12 bytes
1#.=+5=|@-,+
Try it online!
Explanation
This is equivalent to:
1 #. = + 5 = |@- , +
This can be divided into the following fork chain:
(1 #. (= + (5 = (|@- , +))))
Or, visualized using 5!:4<'f'
:
┌─ 1
├─ #.
──┤ ┌─ =
│ ├─ +
└────┤ ┌─ 5
│ ├─ =
└───┤ ┌─ |
│ ┌─ @ ─┴─ -
└───┼─ ,
└─ +
Annotated:
┌─ 1 noun 1
├─ #. base conversion (summation - any?)
──┤ ┌─ = equality
│ ├─ + added to (boolean or)
└────┤ ┌─ 5 noun 5
│ ├─ = is equal to
└───┤ ┌─ | absolute value |
│ ┌─ @ ─┴─ - (of) subtraction |
└───┼─ , paired with |
└─ + subtraction | any of these?
$endgroup$
add a comment |
$begingroup$
J, 12 bytes
1#.=+5=|@-,+
Try it online!
Explanation
This is equivalent to:
1 #. = + 5 = |@- , +
This can be divided into the following fork chain:
(1 #. (= + (5 = (|@- , +))))
Or, visualized using 5!:4<'f'
:
┌─ 1
├─ #.
──┤ ┌─ =
│ ├─ +
└────┤ ┌─ 5
│ ├─ =
└───┤ ┌─ |
│ ┌─ @ ─┴─ -
└───┼─ ,
└─ +
Annotated:
┌─ 1 noun 1
├─ #. base conversion (summation - any?)
──┤ ┌─ = equality
│ ├─ + added to (boolean or)
└────┤ ┌─ 5 noun 5
│ ├─ = is equal to
└───┤ ┌─ | absolute value |
│ ┌─ @ ─┴─ - (of) subtraction |
└───┼─ , paired with |
└─ + subtraction | any of these?
$endgroup$
J, 12 bytes
1#.=+5=|@-,+
Try it online!
Explanation
This is equivalent to:
1 #. = + 5 = |@- , +
This can be divided into the following fork chain:
(1 #. (= + (5 = (|@- , +))))
Or, visualized using 5!:4<'f'
:
┌─ 1
├─ #.
──┤ ┌─ =
│ ├─ +
└────┤ ┌─ 5
│ ├─ =
└───┤ ┌─ |
│ ┌─ @ ─┴─ -
└───┼─ ,
└─ +
Annotated:
┌─ 1 noun 1
├─ #. base conversion (summation - any?)
──┤ ┌─ = equality
│ ├─ + added to (boolean or)
└────┤ ┌─ 5 noun 5
│ ├─ = is equal to
└───┤ ┌─ | absolute value |
│ ┌─ @ ─┴─ - (of) subtraction |
└───┼─ , paired with |
└─ + subtraction | any of these?
answered 2 mins ago
Conor O'BrienConor O'Brien
29.2k263162
29.2k263162
add a comment |
add a comment |
$begingroup$
Dyalog APL, 9 bytes
=∨5∊+,∘|-
Try it online!
$endgroup$
add a comment |
$begingroup$
Dyalog APL, 9 bytes
=∨5∊+,∘|-
Try it online!
$endgroup$
add a comment |
$begingroup$
Dyalog APL, 9 bytes
=∨5∊+,∘|-
Try it online!
$endgroup$
Dyalog APL, 9 bytes
=∨5∊+,∘|-
Try it online!
edited 1 min ago
answered 16 mins ago
dzaimadzaima
14.5k21755
14.5k21755
add a comment |
add a comment |
$begingroup$
Tcl, 58 bytes
proc P a b {expr [set m abs($a-$b)]==5|!$m|abs($a+$b)==5}
Try it online!
$endgroup$
add a comment |
$begingroup$
Tcl, 58 bytes
proc P a b {expr [set m abs($a-$b)]==5|!$m|abs($a+$b)==5}
Try it online!
$endgroup$
add a comment |
$begingroup$
Tcl, 58 bytes
proc P a b {expr [set m abs($a-$b)]==5|!$m|abs($a+$b)==5}
Try it online!
$endgroup$
Tcl, 58 bytes
proc P a b {expr [set m abs($a-$b)]==5|!$m|abs($a+$b)==5}
Try it online!
edited 23 secs ago
answered 6 mins ago
sergiolsergiol
2,5171925
2,5171925
add a comment |
add a comment |
Vikrant Biswas is a new contributor. Be nice, and check out our Code of Conduct.
Vikrant Biswas is a new contributor. Be nice, and check out our Code of Conduct.
Vikrant Biswas is a new contributor. Be nice, and check out our Code of Conduct.
Vikrant Biswas is a new contributor. Be nice, and check out our Code of Conduct.
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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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
$begingroup$
Just for info, you can reduce your 56 by 9 by replacing
x=input();y=input()
withx,y=input()
and giving the input as 2 integers separated by a comma.$endgroup$
– ElPedro
47 mins ago
1
$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
33 mins ago