A forest fire has been spotted at *fire*, a simple 2 element array with x, y coordinates.

The forest service has decided to send smoke jumpers in by plane and drop them in the forest.

The terrain is dangerous and surveyors have determined that there are three possible safe *dropzones*, an array of three simple arrays with x, y coordinates. 

The plane is en route and time is of the essence. Your mission is to return a simple [x,y] array with the coordinates of the dropzone closest to the fire. 

EDIT: 
The airplane is leaving from the origin at 0,0. If your result returns two possible dropzones that are both an equal distance from the fire, choose the dropzone that is closest to 0,0.

If the two dropzones are both equal distance away from 0,0, then return the dropzone that is first in the given array. 

For example, if you are given: fire = [1,1], possibleDZ = [0,1],[1,0],[2,2] . The answer is [0,1] because that is the first possible drop zone in the given array.

Source: codewars | Difficulty: EASY
Tags: Geometry

Fundamentals

Starter code: def dropzone(p, dropzones):
	

Solutions:
from math import hypot

def dropzone(fire, dropzones):
	return min(dropzones, key=lambda p: hypot(p[0] - fire[0], p[1] - fire[1]))


def dropzone(p, dropzones):
	return min(dropzones, key=lambda q: (q[0] - p[0]) ** 2 + (q[1] - p[1]) ** 2)


from scipy.spatial.distance import euclidean

def dropzone(p, dropzones):
	return min(dropzones, key=lambda a: euclidean(a, p))


def dropzone(p, dropzones):
	return min(dropzones, key=lambda d: (p[0] - d[0]) ** 2 + (p[1] - d[1]) ** 2)


from math import sqrt

def dropzone(p, dropzones):
	distances = {sqrt((p[0] - dz[0]) ** 2 + (p[1] - dz[1]) ** 2): dz for dz in dropzones}
	return distances[min(list(distances.keys()))]


def dropzone(p, dropzones):
	distances = []
	for dropzone in dropzones:
		distances.append(((dropzone[0] - p[0]) ** 2 + (dropzone[1] - p[1]) ** 2) ** 0.5)
	return dropzones[distances.index(min(distances))]


def dropzone(p, d):
	(res, ds) = ([], 1000)
	for i in range(0, 3):
		d0 = (p[0] - d[i][0]) ** 2 + (p[1] - d[i][1]) ** 2
		if d0 < ds:
			ds = d0
			res = d[i]
	return res


def dropzone(p, dropzones):
	res = []
	(x1, y1) = (p[0], p[1])
	for dropzone in dropzones:
		(x2, y2) = (dropzone[0], dropzone[1])
		dist = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
		res.append(dist)
	shortest = res.index(min(res))
	return dropzones[shortest]