Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Landing Site solution in Creative category for Landing Site by IRONKAGE
from typing import Set, Iterator, Tuple
import itertools as it
Coords = Tuple[int, int]
def int_coords(cell: str) -> (Coords):
return ord(cell[0]) - ord('A'), ord(cell[1]) - ord('1')
def str_coords(coords: Coords) -> (str):
return chr(ord('A') + coords[0]) + chr(ord('1') + coords[1])
directions = (((1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0), (0, 1)),
((1, 1), (1, 0), (0, -1), (-1, 0), (-1, 1), (0, 1)))
def neighbors(col: int, row: int) -> (Iterator[Coords]):
for c, r in directions[col % 2]:
if 0 <= col + c < 12 and 0 <= row + r < 9:
yield col + c, row + r
def neighboring_area(area: Set[Coords]) -> (Set[Coords]):
return {point for coords in area for point in neighbors(*coords)} - area
def landing_site(obstacles: Set[str]) -> (Set[str]):
obstacles = set(map(int_coords, obstacles))
exterior = set(map(int_coords, it.chain(it.product('@M', '123456789'),
it.product('ABCDEFGHIJKL', '0:'))))
n, cells = 0, neighboring_area(obstacles | exterior)
while True:
next_cells = neighboring_area(cells) - obstacles
if not next_cells:
break
n += 1
obstacles, cells = cells, next_cells
return map(str_coords, cells if n >= 1 else [])
if __name__ == '__main__':
assert landing_site({'E5', 'E7', 'F4', 'F6', 'G4', 'G6', 'H3', 'H5'}) == {'C3', 'J7'}, 'crevasse'
assert landing_site({'A4', 'C2', 'C6', 'C9', 'D4', 'D7', 'F1', 'F5',
'F8', 'G4', 'H7', 'I2', 'I5', 'I9', 'K3', 'K8', 'L5'}) == {'B7', 'E3', 'J6'}, 'stones'
assert landing_site({'D3', 'D4', 'D5', 'D6', 'E3', 'E7', 'F2', 'F7', 'G2',
'G8', 'H2', 'H7', 'I3', 'I7', 'J3', 'J4', 'J5', 'J6'}) == {'G5'}, 'crater'
assert landing_site(set()) == {'E5', 'F5', 'G5', 'H5'}, 'plane'
assert landing_site({chr(c+65)+str(r+1) for c in range(12) for r in range(9)}) == set(), 'wasteland'
print('The local tests are done. Click on "Check" for more real tests.')
Oct. 16, 2019
Comments: