Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Easy and fast solution in Clear category for Pawn Brotherhood by kamilinho20
def safe_pawns(pawns):
tab = ['a','b','c','d','e','f','g','h']
i = 0
safe = 0
col = -1
for a in pawns:
col = tab.index(a[0]) #3
row = int(a[1]) #2
for b in pawns:
if int(b[1]) == row-1 and (tab.index(b[0]) == col-1 or tab.index(b[0]) == col+1):
safe = safe + 1
break
return safe
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert safe_pawns({"b4", "c4", "d4", "e4", "f4", "g4", "e5"}) != 1
#assert safe_pawns({"b4", "d4", "f4", "c3", "e3", "g5", "d2"}) == 6
#assert safe_pawns(["a1","b2","c3","d4","e5","f6","g7","h8"]) != 0
Dec. 13, 2016