6 kyu

Cartesian neighbors distance

41 of 403febonachi

Description:

Previous Cartesian neighbors kata

In previous kata we have been searching for all the neighboring points in a Cartesian coordinate system. As we know each point in a coordinate system has eight neighboring points when we search it by range equal to 1, but now we will change range by third argument of our function (range is always greater than zero). For example if range = 2, count of neighboring points = 24. In this kata grid step is the same (= 1).

It is necessary to write a function that returns array of unique distances between given point and all neighboring points. You can round up the distance to 10 decimal places (as shown in the example). Distances inside list don't have to been sorted (any order is valid).

For Example:

cartesianNeighborsDistance(3, 2, 1) -> {1.4142135624, 1.0}
cartesianNeighborsDistance(0, 0, 2) -> {1.0, 1.4142135624, 2.0, 2.2360679775, 2.8284271247}
cartesianNeighborsDistance(3, 2, 1) -> {1.4142135624, 1.0}
cartesianNeighborsDistance(0, 0, 2) -> {1.0, 1.4142135624, 2.0, 2.2360679775, 2.8284271247}
// please remember the length of the array in this variable
int array_size = 0;
cartesianNeighborsDistance(3, 2, 1, &array_size) -> {1.4142135624, 1.0}
cartesianNeighborsDistance(0, 0, 2, &array_size) -> {1.0, 1.4142135624, 2.0, 2.2360679775, 2.8284271247}
cartesianNeighborsDistance(3, 2, 1) -> {1.4142135624, 1.0}
cartesianNeighborsDistance(0, 0, 2) -> {1.0, 1.4142135624, 2.0, 2.2360679775, 2.8284271247}
CartesianNeighborsDistance(3, 2, 1) -> {1.4142135624, 1.0}
CartesianNeighborsDistance(0, 0, 2) -> {1.0, 1.4142135624, 2.0, 2.2360679775, 2.8284271247}
cartesianNeighborsDistance(3, 2, 1) -> [1.4142135624, 1.0]
cartesianNeighborsDistance(0, 0, 2) -> [1.0, 1.4142135624, 2.0, 2.2360679775, 2.8284271247]
cartesianNeighborsDistance(3, 2, 1) -> [1.4142135624, 1.0]
cartesianNeighborsDistance(0, 0, 2) -> [1.0, 1.4142135624, 2.0, 2.2360679775, 2.8284271247]
cartesian_neighbors_distance(3, 2, 1) -> [1.4142135624, 1.0]
cartesian_neighbors_distance(0, 0, 2) -> [1.0, 1.4142135624, 2.0, 2.2360679775, 2.8284271247]
Fundamentals
Mathematics

More By Author:

Check out these other kata created by febonachi

Stats:

CreatedSep 28, 2017
PublishedOct 3, 2017
Warriors Trained1438
Total Skips243
Total Code Submissions2800
Total Times Completed403
Java Completions41
Python Completions125
C++ Completions59
JavaScript Completions69
Go Completions91
C# Completions39
C Completions31
TypeScript Completions24
Total Stars26
% of votes with a positive feedback rating90% of 141
Total "Very Satisfied" Votes117
Total "Somewhat Satisfied" Votes20
Total "Not Satisfied" Votes4
Total Rank Assessments10
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • febonachi Avatar
  • kazk Avatar
  • Voile Avatar
  • dcieslak Avatar
  • hobovsky Avatar
Ad