Will two kangaroos ever meet after making same number of jumps?
$begingroup$
There are two kangaroos on an x-axis ready to jump in the positive direction (i.e, toward positive infinity). The first kangaroo starts at location $x_1$ and moves at a rate of $v_1$ meters per jump. The second kangaroo starts at location $x_2$ and moves at a rate of $v_2$ meters per jump. Given the starting locations and movement rates for each kangaroo, can you determine if they'll ever land at the same location at the same time?
Input Format
A single line of four space-separated integers denoting the respective values of $x_1$, $v_1$, $x_2$, and $v_2$.
Constraints
- $0 le x_1 < x_2$
- $1 le v_1$
- $1 le v_2$
Output Format
Print YES if they can land on the same location at the same time; otherwise, print NO.
Note: The two kangaroos must land at the same location after making the same number of jumps.
Sample Input 0
0 3 4 2
Sample Output 0
YES
Explanation 0
The two kangaroos jump through the following sequence of locations:
- 0 3 6 9 12
- 4 6 8 10 12
Thus, the kangaroos meet after 4 jumps and we print YES.
Sample Input 1
0 2 5 3
Sample Output 1
NO
Explanation 1
The second kangaroo has a starting location that is ahead (further to the right) of the first kangaroo's starting location (i.e., $x_2 > x_1$). Because the second kangaroo moves at a faster rate (meaning $v_2 > v_1$) and is already ahead of the first kangaroo, the first kangaroo will never be able to catch up. Thus, we print NO.
Note: I searched for the answer and got this puzzle here but without answer :( so had to ask.
mathematics
$endgroup$
add a comment |
$begingroup$
There are two kangaroos on an x-axis ready to jump in the positive direction (i.e, toward positive infinity). The first kangaroo starts at location $x_1$ and moves at a rate of $v_1$ meters per jump. The second kangaroo starts at location $x_2$ and moves at a rate of $v_2$ meters per jump. Given the starting locations and movement rates for each kangaroo, can you determine if they'll ever land at the same location at the same time?
Input Format
A single line of four space-separated integers denoting the respective values of $x_1$, $v_1$, $x_2$, and $v_2$.
Constraints
- $0 le x_1 < x_2$
- $1 le v_1$
- $1 le v_2$
Output Format
Print YES if they can land on the same location at the same time; otherwise, print NO.
Note: The two kangaroos must land at the same location after making the same number of jumps.
Sample Input 0
0 3 4 2
Sample Output 0
YES
Explanation 0
The two kangaroos jump through the following sequence of locations:
- 0 3 6 9 12
- 4 6 8 10 12
Thus, the kangaroos meet after 4 jumps and we print YES.
Sample Input 1
0 2 5 3
Sample Output 1
NO
Explanation 1
The second kangaroo has a starting location that is ahead (further to the right) of the first kangaroo's starting location (i.e., $x_2 > x_1$). Because the second kangaroo moves at a faster rate (meaning $v_2 > v_1$) and is already ahead of the first kangaroo, the first kangaroo will never be able to catch up. Thus, we print NO.
Note: I searched for the answer and got this puzzle here but without answer :( so had to ask.
mathematics
$endgroup$
$begingroup$
What is the source of this puzzle?
$endgroup$
– Dr Xorile
Dec 13 '18 at 15:09
add a comment |
$begingroup$
There are two kangaroos on an x-axis ready to jump in the positive direction (i.e, toward positive infinity). The first kangaroo starts at location $x_1$ and moves at a rate of $v_1$ meters per jump. The second kangaroo starts at location $x_2$ and moves at a rate of $v_2$ meters per jump. Given the starting locations and movement rates for each kangaroo, can you determine if they'll ever land at the same location at the same time?
Input Format
A single line of four space-separated integers denoting the respective values of $x_1$, $v_1$, $x_2$, and $v_2$.
Constraints
- $0 le x_1 < x_2$
- $1 le v_1$
- $1 le v_2$
Output Format
Print YES if they can land on the same location at the same time; otherwise, print NO.
Note: The two kangaroos must land at the same location after making the same number of jumps.
Sample Input 0
0 3 4 2
Sample Output 0
YES
Explanation 0
The two kangaroos jump through the following sequence of locations:
- 0 3 6 9 12
- 4 6 8 10 12
Thus, the kangaroos meet after 4 jumps and we print YES.
Sample Input 1
0 2 5 3
Sample Output 1
NO
Explanation 1
The second kangaroo has a starting location that is ahead (further to the right) of the first kangaroo's starting location (i.e., $x_2 > x_1$). Because the second kangaroo moves at a faster rate (meaning $v_2 > v_1$) and is already ahead of the first kangaroo, the first kangaroo will never be able to catch up. Thus, we print NO.
Note: I searched for the answer and got this puzzle here but without answer :( so had to ask.
mathematics
$endgroup$
There are two kangaroos on an x-axis ready to jump in the positive direction (i.e, toward positive infinity). The first kangaroo starts at location $x_1$ and moves at a rate of $v_1$ meters per jump. The second kangaroo starts at location $x_2$ and moves at a rate of $v_2$ meters per jump. Given the starting locations and movement rates for each kangaroo, can you determine if they'll ever land at the same location at the same time?
Input Format
A single line of four space-separated integers denoting the respective values of $x_1$, $v_1$, $x_2$, and $v_2$.
Constraints
- $0 le x_1 < x_2$
- $1 le v_1$
- $1 le v_2$
Output Format
Print YES if they can land on the same location at the same time; otherwise, print NO.
Note: The two kangaroos must land at the same location after making the same number of jumps.
Sample Input 0
0 3 4 2
Sample Output 0
YES
Explanation 0
The two kangaroos jump through the following sequence of locations:
- 0 3 6 9 12
- 4 6 8 10 12
Thus, the kangaroos meet after 4 jumps and we print YES.
Sample Input 1
0 2 5 3
Sample Output 1
NO
Explanation 1
The second kangaroo has a starting location that is ahead (further to the right) of the first kangaroo's starting location (i.e., $x_2 > x_1$). Because the second kangaroo moves at a faster rate (meaning $v_2 > v_1$) and is already ahead of the first kangaroo, the first kangaroo will never be able to catch up. Thus, we print NO.
Note: I searched for the answer and got this puzzle here but without answer :( so had to ask.
mathematics
mathematics
edited Dec 13 '18 at 9:24
Glorfindel
13.8k35084
13.8k35084
asked Dec 13 '18 at 9:10
Govind PrajapatiGovind Prajapati
1655
1655
$begingroup$
What is the source of this puzzle?
$endgroup$
– Dr Xorile
Dec 13 '18 at 15:09
add a comment |
$begingroup$
What is the source of this puzzle?
$endgroup$
– Dr Xorile
Dec 13 '18 at 15:09
$begingroup$
What is the source of this puzzle?
$endgroup$
– Dr Xorile
Dec 13 '18 at 15:09
$begingroup$
What is the source of this puzzle?
$endgroup$
– Dr Xorile
Dec 13 '18 at 15:09
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
They'll meet if and only if
$v_1 > v_2$ (so that kangaroo 1 catches up)
and
$v_1 - v_2 | x_2 - x_1$, here | means 'is a divisor of'.
Why?
After $n in Bbb{N}$ jumps, kangaroo 1 will be at position $x_1 + n v_1$ and kangaroo 2 at $x_2 + n v_2$. Now, if
$$x_1 + n v_1 = x_2 + n v_2$$
$$n v_1 - n v_2 = x_2 - x_1$$
$$n (v_1 - v_2) = x_2 - x_1$$
$$n = frac{x_2 - x_1}{v_1 - v_2}$$
This fraction is an integer if and only if $v_1 - v_2$ divides $x_2 - x_1$.
$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.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "559"
};
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
},
noCode: 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%2fpuzzling.stackexchange.com%2fquestions%2f76401%2fwill-two-kangaroos-ever-meet-after-making-same-number-of-jumps%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
They'll meet if and only if
$v_1 > v_2$ (so that kangaroo 1 catches up)
and
$v_1 - v_2 | x_2 - x_1$, here | means 'is a divisor of'.
Why?
After $n in Bbb{N}$ jumps, kangaroo 1 will be at position $x_1 + n v_1$ and kangaroo 2 at $x_2 + n v_2$. Now, if
$$x_1 + n v_1 = x_2 + n v_2$$
$$n v_1 - n v_2 = x_2 - x_1$$
$$n (v_1 - v_2) = x_2 - x_1$$
$$n = frac{x_2 - x_1}{v_1 - v_2}$$
This fraction is an integer if and only if $v_1 - v_2$ divides $x_2 - x_1$.
$endgroup$
add a comment |
$begingroup$
They'll meet if and only if
$v_1 > v_2$ (so that kangaroo 1 catches up)
and
$v_1 - v_2 | x_2 - x_1$, here | means 'is a divisor of'.
Why?
After $n in Bbb{N}$ jumps, kangaroo 1 will be at position $x_1 + n v_1$ and kangaroo 2 at $x_2 + n v_2$. Now, if
$$x_1 + n v_1 = x_2 + n v_2$$
$$n v_1 - n v_2 = x_2 - x_1$$
$$n (v_1 - v_2) = x_2 - x_1$$
$$n = frac{x_2 - x_1}{v_1 - v_2}$$
This fraction is an integer if and only if $v_1 - v_2$ divides $x_2 - x_1$.
$endgroup$
add a comment |
$begingroup$
They'll meet if and only if
$v_1 > v_2$ (so that kangaroo 1 catches up)
and
$v_1 - v_2 | x_2 - x_1$, here | means 'is a divisor of'.
Why?
After $n in Bbb{N}$ jumps, kangaroo 1 will be at position $x_1 + n v_1$ and kangaroo 2 at $x_2 + n v_2$. Now, if
$$x_1 + n v_1 = x_2 + n v_2$$
$$n v_1 - n v_2 = x_2 - x_1$$
$$n (v_1 - v_2) = x_2 - x_1$$
$$n = frac{x_2 - x_1}{v_1 - v_2}$$
This fraction is an integer if and only if $v_1 - v_2$ divides $x_2 - x_1$.
$endgroup$
They'll meet if and only if
$v_1 > v_2$ (so that kangaroo 1 catches up)
and
$v_1 - v_2 | x_2 - x_1$, here | means 'is a divisor of'.
Why?
After $n in Bbb{N}$ jumps, kangaroo 1 will be at position $x_1 + n v_1$ and kangaroo 2 at $x_2 + n v_2$. Now, if
$$x_1 + n v_1 = x_2 + n v_2$$
$$n v_1 - n v_2 = x_2 - x_1$$
$$n (v_1 - v_2) = x_2 - x_1$$
$$n = frac{x_2 - x_1}{v_1 - v_2}$$
This fraction is an integer if and only if $v_1 - v_2$ divides $x_2 - x_1$.
edited Dec 13 '18 at 9:20
answered Dec 13 '18 at 9:16
GlorfindelGlorfindel
13.8k35084
13.8k35084
add a comment |
add a comment |
Thanks for contributing an answer to Puzzling Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
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%2fpuzzling.stackexchange.com%2fquestions%2f76401%2fwill-two-kangaroos-ever-meet-after-making-same-number-of-jumps%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
$begingroup$
What is the source of this puzzle?
$endgroup$
– Dr Xorile
Dec 13 '18 at 15:09