Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Set intersection solution in Clear category for Pawn Brotherhood by Leonix
def safe_pawns(pawns):
""" 1) Build a set of coordinates threatened by all pawns.
2) Count how many pawns are placed in coordinates from (1).
"""
threatened = sum((attack_squares(pawn) for pawn in pawns), ())
return len(pawns.intersection(threatened))
def attack_squares(pawn):
# This might return coordinates not present in real chess boards, e.g.: i9.
# But since it does not matter for our purposes, we don't bother to check.
row = str(1+int(pawn[1]))
left_col = chr(ord(pawn[0])-1)
right_col = chr(ord(pawn[0])+1)
return left_col + row, right_col + row
Aug. 5, 2015