Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Colder-Warmer by Moff
from math import hypot
def checkio(steps):
used_coords = {(r, c) for r, c, cw in steps}
if len(steps) == 0:
return 5, 5
elif len(steps) == 1:
return 5, 0
else:
field = {(r, c) for r in range(10) for c in range(10)}
for i in range(1, len(steps)):
r1, c1, cw1 = steps[i-1]
r2, c2, cw2 = steps[i]
for r in range(10):
for c in range(10):
d1 = hypot(r - r1, c - c1)
d2 = hypot(r - r2, c - c2)
if (cw2 == 0 and d1 != d2) or (cw2 == -1 and d1 > d2) or \
(cw2 == 1 and d1 < d2):
field.discard((r, c))
for coord in used_coords:
field.discard(coord)
field = sorted(field)
return field[len(field) // 2]
Sept. 1, 2015