For this kata, you are given three points ```(x1,y1,z1)```, ```(x2,y2,z2)```, and ```(x3,y3,z3)``` that lie on a straight line in 3-dimensional space.
You have to figure out which point lies in between the other two.

Your function should return 1, 2, or 3 to indicate which point is the in-between one.

Source: codewars | Difficulty: EASY
Tags: Geometry

Fundamentals

Mathematics

Starter code: def middle_point(x1, y1, z1, x2, y2, z2, x3, y3, z3):
	

Solutions:
def middle_point(x1, y1, z1, x2, y2, z2, x3, y3, z3):
	return sorted(((x1, y1, z1, 1), (x2, y2, z2, 2), (x3, y3, z3, 3)))[1][3]


def middle_point(*coords):
	return sorted(((coords[i * 3:i * 3 + 3], i + 1) for i in range(3)))[1][-1]


import math

def middle_point(x1, y1, z1, x2, y2, z2, x3, y3, z3):
	distances = [math.pow(x1 - x2, 2.0) + math.pow(y1 - y2, 2.0) + math.pow(z1 - z2, 2.0), math.pow(x1 - x3, 2.0) + math.pow(y1 - y3, 2.0) + math.pow(z1 - z3, 2.0), math.pow(x3 - x2, 2.0) + math.pow(y3 - y2, 2.0) + math.pow(z3 - z2, 2.0)]
	maximum = max(distances)
	index = distances.index(maximum)
	return 3 - index


def middle_point(x1, y1, z1, x2, y2, z2, x3, y3, z3):
	import math

	def dist(x1, y1, z1, x2, y2, z2):
		return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2 + (z1 - z2) ** 2)
	if math.fabs(dist(x1, y1, z1, x2, y2, z2) + dist(x1, y1, z1, x3, y3, z3) - dist(x2, y2, z2, x3, y3, z3)) < 0.1:
		return 1
	if math.fabs(dist(x2, y2, z2, x1, y1, z1) + dist(x2, y2, z2, x3, y3, z3) - dist(x1, y1, z1, x3, y3, z3)) < 0.1:
		return 2
	return 3


def middle_point(*args):
	sortLst = sorted((args[i:i + 3] for i in range(0, 9, 3)))
	return [i for i in range(0, 9, 3) if args[i:i + 3] == sortLst[1]][0] / 3 + 1


middle_point = lambda *a: sorted((a[i - 3:i] + (i // 3,) for i in (3, 6, 9)))[1][3]


def middle_point(*coords):
	c = sorted((coords[i::3] for i in range(3)), key=lambda c: -len(set(c)))[0]
	return c.index(sorted(c)[1]) + 1


def middle_point(x1, y1, z1, x2, y2, z2, x3, y3, z3):
	x2x3 = x2 <= x1 <= x3 if x2 < x3 else x3 <= x1 <= x2
	y2y3 = y2 <= y1 <= y3 if y2 < y3 else y3 <= y1 <= y2
	z2z3 = z2 <= z1 <= z3 if z2 < z3 else z3 <= z1 <= z2
	x1x3 = x1 <= x2 <= x3 if x1 < x3 else x3 <= x2 <= x1
	y1y3 = y1 <= y2 <= y3 if y1 < y3 else y3 <= y2 <= y1
	z1z3 = z1 <= z2 <= z3 if z1 < z3 else z3 <= z2 <= z1
	x1x2 = x1 <= x3 <= x2 if x1 < x2 else x2 <= x3 <= x1
	y1y2 = y1 <= y3 <= y2 if y1 < y2 else y2 <= y3 <= y1
	z1z2 = z1 <= z3 <= z2 if z1 < z2 else z2 <= z3 <= z1
	if x2x3 and y2y3 and z2z3:
		return 1
	if x1x3 and y1y3 and z1z3:
		return 2
	if x1x2 and y1y2 and z1z2:
		return 3