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 Luis_Zamora_Veliz
import numpy as np
def safe_pawns(pawns):
dict={"a":0,"b":1,"c":2,"d":3,"e":4,"f":5,"g":6,"h":7}
cont=0
tableto = np.zeros((8,8))
for coord in pawns:
i=8-int(coord[1])
j=dict[coord[0]]
tableto[i,j]=1
g,f = tableto.shape
for i in range(g):
for j in range(f):
if tableto[i,j] ==1:
if tableto[i+1:i+2,j-1:j] == 1 or tableto[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: