Last active
December 28, 2016 08:20
-
-
Save dividead/07a4beb23fb8f2e38817 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
dots = [[2,2],[9,7],[1,1],[5,5],[2,3]] | |
#расчет расстояния между двумя точками | |
def dst(a, b): | |
return math.sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2) | |
#поиск всех соседей для заданной точки, ее радиус и кол-во соседей | |
def srch(dot): | |
evrthng = filter(None, map(lambda x: dst(dot,x), dots)) | |
radius = min(evrthng) | |
near = filter(lambda x: x <= radius*2, evrthng) | |
print dot, radius, len(near) | |
#обход каждой точки | |
for dot in dots: | |
srch(dot) | |
#[2, 2] 1.0 2 | |
#[9, 7] 4.472135955 3 | |
#[1, 1] 1.41421356237 2 | |
#[5, 5] 3.60555127546 4 | |
#[2, 3] 1.0 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment