Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
pawns_ord-comprehension-tuples solution in Clear category for Pawn Brotherhood by nazarstakhovskyi
def safe_pawns(pawns: set) -> int:
a = [(int(i[1]), ord(i[0]) - 96) for i in pawns]
count = 0
for row, col in a:
safe = ((row - 1, col - 1) in a) or ((row - 1, col + 1) in a)
if safe:
count += 1
return count
# there is a bug in the "asserts" - the first value should be changed to 5, otherwise it won't work
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert safe_pawns({"a4", "d4", "f4", "c3", "e3", "g5", "d2"}) == 5
assert safe_pawns({"b4", "c4", "d4", "e4", "f4", "g4", "e5"}) == 1
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
June 3, 2021