All pastes #2126212 Raw Edit

Untitled

public text v1 · immutable
#2126212 ·published 2012-03-08 20:07 UTC
rendered paste body
f=open("points.txt","r")
points_set = set()
num_squares = 0

for line in f:
    line = line.rstrip('\n')
    point = line.split()
    i = 0
    
    while i < len(point):
        coordinate = point[i]
        point[i] = int(coordinate)
        i += 1
    
    point = tuple(point)
    points_set.add(point)
    
points_list = list(points_set)

for point in points_list:
    (x, y) = point
    same_x_points = []
    
    for neighbour in points_set:
        if neighbour != point:
            if neighbour[0] == point[0]:
                same_x_points.append(neighbour)
    
    for neighbour in same_x_points:
        (x_neighbour, y_neighbour) = neighbour
        length = abs(y - y_neighbour)
        x1 = x - length
        x2 = x + length
        if (x1, y) in points_set and (x1, y_neighbour) in points_set:
            num_squares += 1
        if (x2, y) in points_set and (x2, y_neighbour) in points_set:
            num_squares += 1
    

            
    points_set.remove(point)
    
print num_squares