Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Heatmap solution in Clear category for Colder-Warmer by martin_b
from math import hypot
def checkio(steps):
map, visited = [0] * 100, set()
px, py, _ = steps[0]
visited.add(10 * px + py)
# heat map - increment points on the map which fulfill the step result
for cx, cy, ch in steps[1:]:
visited.add(10 * cx + cy)
for t in range(100):
tx, ty = divmod(t, 10)
h = hypot(px - tx, py - ty) - hypot(cx - tx, cy - ty)
if int(h >= 0) - int(h <= 0) == ch:
map[t] += 1
px, py = cx, cy
# next step in the center of the max of the heat map, very crude algorithm
next = sorted(((h, i) for i, h in enumerate(map) if not i in visited))
m = next[-1][0]
next = [i for h, i in next if h == m]
return divmod(next[len(next) // 2], 10)
Nov. 24, 2017
Comments: