Start Blizzard

This commit is contained in:
2019-12-23 17:19:33 +01:00
parent b658dcead9
commit 08b4100a7e
5 changed files with 166 additions and 0 deletions

21
Home/pawn-brotherhood.py Normal file
View File

@@ -0,0 +1,21 @@
def safe_pawns(pawns: set) -> int:
cols = "abcdefgh"
safe_count = 0
for pawn in pawns:
row = int(pawn[1])
if row == 1:
continue
col_index = cols.index(pawn[0])
protector_1 = cols[col_index - 1] + str(row - 1) if col_index - 1 >= 0 else None
protector_2 = cols[col_index + 1] + str(row - 1) if col_index + 1 < len(pawns) and row > 1 else None
if protector_1 in pawns or protector_2 in pawns:
safe_count += 1
return safe_count
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
assert safe_pawns({"a1", "b2", "c3", "d4", "e5", "f6", "g7", "h8"}) == 8
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")