Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Colder-Warmer by flpo
from functools import partial
from itertools import chain
from math import sqrt
from operator import eq, gt, lt
GRID_INDICES = [(i, j) for j in range(10) for i in range(10)]
OPERATIONS = {0: eq, 1: gt, -1: lt}
def distance(p, q):
return sqrt((q[0] - p[0])**2 + (q[1] - p[1])**2)
def checkio(history):
candidates = set(GRID_INDICES)
for h0, h1 in zip(history, history[1:]):
candidates.difference_update({p for p in candidates if not OPERATIONS[h1[2]](distance(h0[:2], p), distance(h1[:2], p))})
return max(candidates, key=partial(distance, history[-1][:2]))
July 3, 2017
Comments: