Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Pawn Brotherhood by Adam_Navarrete
from numpy import*
def safe_pawns(pawns):
a1=0
diccionario={"a":0, "b":1, "c":2, "d":3, "e":4, "f":5, "g":6, "h":7}
ta=zeros((8,8))
for a in pawns:
i=8-int(a[1])
j=diccionario[a[0]]
ta[i,j]=1
a1=0
f,c=ta.shape
for i in range(f):
for j in range(c):
if ta[i,j]==1:
if ta[i+1:i+2,j-1:j]==1 or ta[i+1:i+2,j+1:j+2]==1:
a1=a1+1
return a1
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
Jan. 19, 2017
Comments: