Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Quick and dirty solution in Creative category for Safe Coasts by veky
def finish_map(regional_map):
M = [bytearray(x.replace(".", "S"), "ascii") for x in regional_map]
def t(i, j):
if i in range(len(M)) and j in range(len(M[i])) and M[i][j] in b'S' \
and set(b''.join(M[k][max(j - 1, 0) : j + 2]
for k in range(i - 1, i + 2) if k in range(len(M)))) \
<= set(b'SD'):
M[i][j] = b'D'[0]
nonlocal dirty
dirty = True
dirty = True
while dirty:
dirty = False
for i, row in enumerate(M):
for j, cell in enumerate(row):
if cell in b'D':
t(i + 1, j)
t(i - 1, j)
t(i, j - 1)
t(i, j + 1)
return tuple(map(bytearray.decode, M))
Aug. 31, 2014