20
1
Think of a road as a number line, starting at 0
and continuing indefinitely:
.................................................................
There are two cars on the road: C
and R
. C
is the cop who is trying to catch R
, the robber. C
starts at 0
, and R
starts somewhere on the road:
C.............................R..................................
The cop is already moving - he's chasing the robber. He has a constant speed. The robber just hopped into his car. He's accelerating. Each tick, the robber's speed increases by his acceleration.
Say the cop's speed is 7
and the robber's acceleration is 1
. If the robber starts at 30
, this is what the road would look like each tick:
C.............................R..................................
.......C.......................R.................................
..............C..................R...............................
.....................C..............R............................
............................C...........R........................
...................................C.........R...................
..........................................C........R.............
.................................................C........R......
After the last tick above, the robber's speed is equal to the cop's, and he's still ahead. Since the cop is moving at a constant speed and the robber is still speeding up, the robber escapes, so you output a truthy value. However, if the cop's speed had been 9
...
C.............................R..................................
.........C.....................R.................................
..................C..............R...............................
...........................C........R............................
....................................C...R........................
.............................................X...................
... then the cop catches up to the robber before the robber can get away (marked by the X
), so you output a falsey value.
Your Task
Given three inputs - the cop's speed, the robber's position, and the robber's acceleration - determine whether or not the robber will get away.
Rules
- The cop always starts at
0
. - All inputs will be positive integers.
- The cop catches the robber if, after any tick, the cop's position is greater than or equal to the robber's position.
- The robber gets away when he hasn't been caught yet and his speed is greater than the cop's.
- Your program must terminate after output.
- The robber accelerates before he moves each tick.
Test Cases
Cop Speed, Robber Position, Robber Acceleration -> Output
7, 30, 1 -> truthy
9, 30, 1 -> falsey
2, 1, 3 -> truthy
100, 100, 50 -> truthy
60, 60, 20 -> falsey
10, 1, 1 -> falsey
10, 50, 2 -> truthy
11, 50, 2 -> truthy
12, 50, 2 -> truthy
13, 50, 2 -> truthy
14, 50, 2 -> truthy
15, 50, 2 -> truthy
16, 50, 2 -> falsey
17, 50, 2 -> falsey
18, 50, 2 -> falsey
100, 451, 10 -> truthy
Reference Python 3 implementation that creates a visual also: Try it online!
This is code-golf, so shortest answer in bytes wins.
Sandbox (deleted) – Stephen – 2017-08-11T20:06:32.167
8Ohhhh... this isn't a cops and robbers challenge; that makes more sense. – Magic Octopus Urn – 2017-08-11T20:41:35.347
Is the input guaranteed to be in the given format, or can we take input in whatever format we want (like
robber acceleration, cop speed, robber position
instead)? – TehPers – 2017-08-11T20:47:18.317@TehPers whatever you want (consistent each time), but if you're doing something different say so in your answer – Stephen – 2017-08-11T20:48:20.380
2Test case request: 100, 451, 10. (The answers don't all agree on the result). – Neil – 2017-08-11T23:35:01.547
@Neil added, good test case since cop is next to robber twice – Stephen – 2017-08-11T23:51:27.607