5 kyu
Find the "center" point
55 of 70myjinxin2015
Description:
When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said
Description:
There is a matrix that contains some points(Use A-Z to represent them).
. . . . . .
. . A . . .
. . . . . .
. . . . . .
. . D . . .
B . . . . C
Find out the "center" point(s) which has the minimum sum of the pythagorean distances to the other points.
In the example above, the "center" point is "D", so the result is ["D"]
.
Arguments:
matrix
: A string that containsA,B,C..
. Each row is separated by "\n". Each point is separated by space(Please ignore space when you calculate the distance ;-) An example: In matrix above, the distance from B to C is 5, not 10 ;-))
Results & Note:
- Returns an array that contains all "center" point(s).
- If more than one points are found, sort them according to the order A-Z.
- How to compare two distance are same? In the calculation process, the float numbers have the precision problem. So, we should rounding number to 6 decimal places, and then compare them.
- You can assume that there are at least two points in the matrix, up to 26 points.
Some Examples
matrix=
. . . . . .
. . A . . .
. . . . . .
. . . . . .
. . D . . .
B . . . . C
findCenterPoints(matrix) === ["D"]
matrix=
A . . . . B
. . . . . .
. . . F . .
. . E . . .
. . . . . .
D . . . . C
findCenterPoints(matrix) === ["E","F"]
Puzzles
Similar Kata:
Stats:
Created | Oct 31, 2016 |
Published | Oct 31, 2016 |
Warriors Trained | 164 |
Total Skips | 3 |
Total Code Submissions | 566 |
Total Times Completed | 70 |
JavaScript Completions | 55 |
Python Completions | 19 |
Total Stars | 4 |
% of votes with a positive feedback rating | 95% of 29 |
Total "Very Satisfied" Votes | 26 |
Total "Somewhat Satisfied" Votes | 3 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 5 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |