Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Pawn Brotherhood by dominikbrandon
def safe_pawns(pawns):
array = ["z","a","b","c","d","e","f","g","h","z"]
counter = 0
for row in range(2, 9):
for column in range(1, 9):
if (array[column] + str(row)) in pawns:
if (array[column - 1] + str(row - 1)) in pawns:
counter += 1
elif (array[column + 1] + str(row - 1)) in pawns:
counter += 1
column += 1
row += 1
return counter
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. 17, 2016