Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Pawn Brotherhood by wolicki.mikolaj
def safe_pawns(pawns):
indeksy = set()
for p in pawns:
row = int(p[1]) - 1
col = ord(p[0]) - 97
indeksy.add((row, col))
wynik = 0
#print indeksy
for row, col in indeksy:
bezpieczny = ((row - 1, col - 1) in indeksy) or ((row - 1, col + 1) in indeksy)
if bezpieczny:
wynik += 1
return wynik
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
Nov. 28, 2016