Jumping Kangaroos
Description:
Adapted from here, with less terrible instructions and a couple tweaks.
Two kangaroos are jumping on a line. They start out at different points on the line, and jump in the same direction at different speeds. Your task is to determine whether or not they'll ever land in the same spot at the same time (you'll just have to suspend disbelief for a moment and accept that two kangaroos, for the purpose of this kata, can occupy the same space at the same time :)
Your function is given four arguments (kanga1, rate1, kanga2, rate2)
; the first kangaroo's starting point, the first kangaroo's speed, the second kangaroo's starting point, and the second kangaroo's speed.
Return true
if the above conditions are met, else false
. Starting location and speed may vary wildly. The first kangaroo will usually start behind the second one and travel faster, but not always. Starting locations may be negative, but speeds will always be > 0.
Example:
kangaroo(kanga1 = 0, speed1 = 3, kanga2 = 4, speed2 = 2)=> true //they meet on their fourth jump
Other examples:
kangaroo(0,2,5,3)=> false //the first kangaroo starts behind, moves slower, and never catches up
Brute force solutions are possible (and not discouraged), but you'll save yourself a lot of waiting time if you don't go that route :)
Good luck!
Similar Kata:
Stats:
Created | May 1, 2018 |
Published | May 5, 2018 |
Warriors Trained | 1239 |
Total Skips | 17 |
Total Code Submissions | 2521 |
Total Times Completed | 543 |
JavaScript Completions | 289 |
Ruby Completions | 51 |
Python Completions | 238 |
Total Stars | 29 |
% of votes with a positive feedback rating | 89% of 136 |
Total "Very Satisfied" Votes | 109 |
Total "Somewhat Satisfied" Votes | 25 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 3 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |