Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Pawn Brotherhood by omegabyte31
# migrated from python 2.7
def safe_pawns(pawns):
# Convert chess positions to (relative) coordinates.
coordlist = [(ord(x[0]), ord(x[1])) for x in pawns]
# Get coords of safe pawns. Safe pawns have a 'guarding' pawns, whose
# '1-8' coord is one smaller and 'a-h' coord is 1 larger or 1 smaller.
safepawncoords = [ia_i1 for ia_i1 in coordlist if (ia_i1[0]+1, ia_i1[1]-1) in coordlist\
or (ia_i1[0]-1, ia_i1[1]-1) in coordlist]
return len(safepawncoords)
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert safe_pawns({"b4", "d4", "f4", "c3", "e3", "g5", "d2"}) == 6
assert safe_pawns({"b4", "c4", "d4", "e4", "f4", "g4", "e5"}) == 1
Oct. 27, 2015
Comments: