Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in 3rd party category for Pawn Brotherhood by Angel_Nie
import numpy as np
def safe_pawns(pawns):
cont=0
dict={"a":0,"b":1,"c":2,"d":3,"e":4,"f":5,"g":6,"h":7}
tablero=np.zeros((8,8))
for coord in pawns:
i=8-int(coord[1])
j=dict[coord[0]]
tablero[i,j]=1
f,c=tablero.shape
cont=0
for i in range(f):
for j in range(c):
if tablero[i,j]==1:
if tablero[i+1:i+2,j-1:j]==1 or tablero[i+1:i+2,j+1:j+2]==1:
cont+=1
return cont
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: