Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Pawn Brotherhood by testarossa
def safe_pawns(pawns):
pionki = list(pawns)
tablica= [0]*8
for i in range(8):
tablica[i]=[0]*8
for i in pionki:
wiersz=ord(i[1])-ord("0")-1
kolumna=ord(i[0])-ord("a")
tablica[wiersz][kolumna]=1
for i in range(7, -1, -1):
for j in range(8):
print(tablica[i][j], end = " ")
print()
x=0
p=0
for i in pionki:
wiersz=ord(i[1])-ord("0")-1
kolumna=ord(i[0])-ord("a")
if wiersz>=1 and kolumna>=1:
if tablica[wiersz-1][kolumna-1]==1:
x=x+1
if wiersz>=1 and kolumna<=6:
if(tablica[wiersz-1][kolumna+1]==1):
x=x+1
if x==2:
p=p+1
x=0
elif x==1:
p=p+1
x=0
return p
#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
Nov. 19, 2016