Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Colder-Warmer - Bisections solution in Uncategorized category for Colder-Warmer by capback250
def checkio(args):
can = []
ans = {0: [5, 5], 1: [5, 0]}
if len(args) in ans:
return ans[len(args)]
for x in [[x, y] for x in range(10) for y in range(10)]:
if analyz(args, x):
can.append(x)
for coord in args:
fck = [coord[0], coord[1]]
if fck in can:
del can[can.index(fck)]
return sorted(can)[len(can) // 2]
def analyz(args, possible):
summa = 0
for i in range(len(args)-1):
logic = args[i+1][2]
a, b = args[i], args[i+1]
fa = ((possible[0] - a[0])**2 + (possible[1] - a[1])**2) ** .5
fb = ((possible[0] - b[0])**2 + (possible[1] - b[1])**2) ** .5
if logic == -1:
if fa < fb:
summa += 1
if logic == 1:
if fa > fb:
summa += 1
if logic == 0:
if fa == fb:
summa += 1
return summa == len(args) -1
Jan. 25, 2016