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 contains A,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

Stats:

CreatedOct 31, 2016
PublishedOct 31, 2016
Warriors Trained164
Total Skips3
Total Code Submissions566
Total Times Completed70
JavaScript Completions55
Python Completions19
Total Stars4
% of votes with a positive feedback rating95% of 29
Total "Very Satisfied" Votes26
Total "Somewhat Satisfied" Votes3
Total "Not Satisfied" Votes0
Total Rank Assessments5
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • Voile Avatar
  • dfhwze Avatar
Ad