Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Pawn Brotherhood by Rafal__Kotas
def safe_pawns(pawns):
x=list(pawns)
safe=0
a =[[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0]]
b =[['a8','b8','c8','d8','e8','f8','g8','h8'],
['a7','b7','c7','d7','e7','f7','g7','h7'],
['a6','b6','c6','d6','e6','f6','g6','h6'],
['a5','b5','c5','d5','e5','f5','g5','h5'],
['a4','b4','c4','d4','e4','f4','g4','h4'],
['a3','b3','c3','d3','e3','f3','g3','h3'],
['a2','b2','c2','d2','e2','f2','g2','h2'],
['a1','b1','c1','d1','e1','f1','g1','h1']]
y=0
z=0
Y=0
#umieszczanie pionków o wspołrzędnych z listy x na szachownicy(w tab. a 0 --> 1)
for i in range(8):
for j in range(8):
for k in range (len(x)):
if (x[k]==b[i][j]):
a[i][j]=1
for i in range(8):
for j in range(8):
y=0
z=0
if(a[i][j]==1):
if(i+1<8 and j+1<8):
if(a[i+1][j+1]==1):
y=1
if(i+1<8 and j-1>=0):
if(a[i+1][j-1]==1):
z=1
if(y==1 or z==1):
safe=safe+1
return (safe)
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. 6, 2016