Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Use infos to filter grid cells and pick any cell solution in Clear category for Colder-Warmer by Phil15
from math import hypot
GRID = {(r, c) for r in range(10) for c in range(10)}
def checkio(steps):
"""Colder-Warmer solver."""
# All unvisited cells.
cells = GRID - {(r, c) for r, c, _ in steps}
# Filter the cells with the each "colder/same/warmer" info.
for (*prev, _), (*current, info) in zip(steps, steps[1:]):
cells = {pos for pos in cells if use_info(prev, current, info, pos)}
print(len(cells))
return cells.pop() # Pick any (possible) cell.
def use_info(previous, current, info, position) -> bool:
"""Say if the given position is possible according to the info."""
dp, dc = distance(*position, *previous), distance(*position, *current)
return dp == dc if not info else (dp > dc if info > 0 else dp < dc)
def distance(x1, y1, x2, y2) -> float: return hypot(x2 - x1, y2 - y1)
April 4, 2020
Comments: