All problems
Count Boomerangs
Problem
Count the ordered triples (i, j, k) of distinct points where the distance from i to j equals the distance from i to k, making i the boomerang tip.
For each point i, group all squared distances to the other points and add c * (c - 1) for every distance with count c. Squared distances avoid floating point errors.
Hint
For a fixed tip, any two points at the same distance form two ordered boomerangs.
Test cases
case 1
in: [[[0,0],[1,0],[2,0]]]
expected: 2
case 2
in: [[[1,1],[1,1],[1,1]]]
expected: 6
case 3
in: [[[0,0],[1,0]]]
expected: 0
case 4
in: [[[1,1],[2,2],[3,3]]]
expected: 2
Starter codePython
def count_boomerangs(points):
# Your code here
pass4 test cases · run your code against them in the editor