Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Pawn Brotherhood by slygoblin
def safe_pawns(pawns):
counter = 0
table = ["a", "b", "c", "d", "e", "f", "g", "h"]
pawn1 = ""
pawn2 = ""
for i in pawns:
for j in [0,1,2,3,4,5,6,7]:
if table[j] == i[0]:
if j-1 >= 0 and int(i[1])-1 > 0:
pawn1 = table[j-1] + str(int(i[1])-1)
if j+1 < 8 and int(i[1])-1 > 0:
pawn2 = table[j+1] + str(int(i[1])-1)
break
if pawn1 in pawns:
counter += 1
pawn1 = ""
pawn2 = ""
if pawn2 in pawns:
counter += 1
pawn1 = ""
pawn2 = ""
return counter
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
Dec. 11, 2015