Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
13-liner: simple solution in Clear category for Landing Site by przemyslaw.daniel
def hex_distance(cell1, cell2):
(aq, ar), (bq, br) = map(ord, cell1), map(ord, cell2)
ar, br = ar - (aq - 1) // 2, br - (bq - 1) // 2
return (abs(aq - bq) + abs(aq + ar - bq - br) + abs(ar - br)) // 2
def landing_site(obstacles):
from collections import Counter
cells = {x+y for x in 'ABCDEFGHIJKL' for y in '123456789'}
cells, out = cells - obstacles, {}
for cell in cells:
count = Counter(hex_distance(cell, c) for c in cells)
out[cell] = next(r for r in range(1, 9) if count[r] != 6*r)
return {cell for cell in out if out[cell] == max(out.values()) and out[cell] > 1}
Aug. 28, 2019
Comments: