Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Clear, simple, yet efficient solution solution in Clear category for Pawn Brotherhood by dunpealer
from collections import namedtuple
def safe_pawns(pawns):
Pawn = namedtuple('Pawn', ['col', 'row'])
positions = set(Pawn(ord(pawn[0]) - ord('a'), int(pawn[1])) for pawn in pawns)
safe = set() # safe positions
for pawn in positions:
if pawn.row == 8:
continue
next_row = pawn.row + 1
if pawn.col > 0:
safe.add((pawn.col - 1, next_row))
if pawn.col < 7:
safe.add((pawn.col + 1, next_row))
return len(positions & safe)
Aug. 15, 2015
Comments: