Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
simple flood fill, complex coordinates with transformed axis solution in Clear category for Supply Line by juestr
transform = lambda xy: ord(xy[0]) + (ord(xy[1]) - (ord(xy[0])-1) // 2) * 1j
grid = {transform(x+y) for x in 'ABCDEFGHIJKL' for y in '123456789'}
directions = (1, -1, 1j, -1j, 1-1j, -1+1j)
def supply_line(you, depots, enemies):
you = transform(you)
depots, enemies = ({transform(x) for x in xs} for xs in (depots, enemies))
unexplored = grid - enemies - {e + d for e in enemies for d in directions}
distance, active = 0, {you}
while active:
unexplored -= active
distance += 1
active = {hex + d for hex in active for d in directions if hex + d in unexplored}
if active & depots:
return distance
return None
Oct. 31, 2019
Comments: