Simple Fun #222: Gold Mine Race
Description:
Story
On a particular continent far far away, a precious gold mine was reported to be found. Every country started to gather up armies and went for the mine. Only one will dominate!
.
Task
Given the x and y coordinates of each city on the continent, the coordinates of the goldmine and speed
of each army, determine which city will take over the gold mine if all armies start to move from the cities simultaneously.
The first army to reach the mine captures it. However, if two or more armies reach the gold mine at the same time, they will fight to death, so none of them will get it.
Returns the 0-based index
of the city that will dominate, or -1
if no one will.
.
Input/Output
[input]
2D integer array cities
A matrix of cities' coordinates in the format [x, y].
[input]
float array speed
Array of the same length as cities
, speed[i] is the speed of the army from cities[i].
[input]
integer array goldmine
The mine's coordinates in the format [x, y]
.
[output]
an integer
The 0-based index
of the city that will dominate, or -1
if no one will.
.
Example
For cities = [[3,0],[2,0],[0,1]], speed = [3,3,3] and goldmine = [0, 0]
,
the output should be 2
.
The armies travel with the same speed, but the second city (0-based) is closer to the gold mine than other two, so their army will reach the mine first.
For cities = [[-3,-4],[3,4],[-3,4],[3,-4]], speed = [2, 2, 5, 5] and goldmine = [0, 0]
,
the output should be -1
.
At first armies from cities 2 and 3 will meet and fight to death. After some time, armies from cities 0 and 1 will battle for the mine and die a heroic death. Thus, no one will conquer the mine, so the answer is -1
.
Similar Kata:
Stats:
Created | Apr 28, 2017 |
Published | Apr 28, 2017 |
Warriors Trained | 282 |
Total Skips | 26 |
Total Code Submissions | 402 |
Total Times Completed | 76 |
JavaScript Completions | 62 |
Haskell Completions | 18 |
Total Stars | 7 |
% of votes with a positive feedback rating | 88% of 34 |
Total "Very Satisfied" Votes | 28 |
Total "Somewhat Satisfied" Votes | 4 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 13 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 8 kyu |