Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
[200th mission] DFS and great neighbors function solution in Clear category for Safe Coasts by Phil15
from itertools import product
MOVES = [move for move in product((-1,0,1), repeat=2) if move!=(0,0)] # 8 moves
SHIP_MOVES = [(i,j) for (i,j) in MOVES if abs(i)+abs(j)==1] # 4 moves N-S-E-W
WATER, LAND, DANGER, SAFE = '.XDS'
def finish_map(map):
"""Know coasts then ghost territory (with DFS). What remains is safe."""
r, c = len(map), len(map[0])
neighbors = lambda i, j, moves, elem: ((i+I, j+J) for I, J in moves
if 0<=i+I
Sept. 18, 2018
Comments: