Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
ndimage solution in 3rd party category for Safe Coasts by gyahun_dash
from scipy import array, equal, ones, select
from scipy.ndimage import binary_dilation, label
def finish_map(region):
grid = array(list(map(list, region)))
lands, ships = [grid == symbol for symbol in 'XD']
zones, num = label(~binary_dilation(lands, structure=ones([3, 3])))
segments = equal.outer(range(1, num + 1), zones)
dangers = segments[(ships & segments).any(axis=(1, 2))].any(axis=0)
return list(map(''.join, select([lands, dangers], ['X', 'D'], 'S')))
Jan. 9, 2017
Comments: