Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Pawn Brotherhood by logicalladybuglifestyle
def safe_pawns(pawns: set) -> int:
h_label = '_abcdefgh_'
v_label = '_12345678_'
safe = 0
for k in pawns:
r_b = h_label[h_label.find(k[0]) - 1] + v_label[v_label.find(k[1]) - 1]
l_b = h_label[h_label.find(k[0]) + 1] + v_label[v_label.find(k[1]) - 1]
if r_b in pawns or l_b in pawns:
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
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
Feb. 10, 2020