Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Convertion to numerics solution in Clear category for Pawn Brotherhood by igharok
def safe_pawns(pawns: set) -> int:
### Converting alphanumerical notation to numerical coordinates:
set_pawn = {(ord(iter_coord[0]) - ord('a') + 1) * 10 + int(iter_coord[1]) for iter_coord in pawns}
### Diagonal defence checking:
num_result = sum((((iter_pawn - 11) in set_pawn) | ((iter_pawn + 9) in set_pawn)) for iter_pawn in set_pawn)
return num_result
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
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
Feb. 19, 2020
Comments: