Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
deqtuenary solution in Clear category for Landing Site by veky
import typing, collections, itertools, string
def neighbors(hex):
j, i = hex
for t in -1, 1:
yield j, i + t
for s in 0, (-1)**j: yield j + t, i + s
to_coords = lambda hex: (int(hex[0], 36) - 9, int(hex[1]))
from_coords = lambda hex: string.ascii_uppercase[hex[0] - 1] + str(hex[1])
visible = {*itertools.product(range(1, 13), range(1, 10))}
outer = {*itertools.product(range(-1, 15), range(-1, 12))} - visible
def landing_site(obstacles: {str}) -> {str}:
obstacles = {*map(to_coords, obstacles)} | outer
free = visible - obstacles
q = collections.deque((pos, 0) for pos in obstacles)
distance = {}
while q:
old, n = q.popleft()
distance[old] = n
for new in neighbors(old):
if new in free: q.append((new, n + 1))
free.discard(new)
md = max(distance.values())
return {from_coords(pos) for pos, d in distance.items() if d == md > 1}
Aug. 25, 2019