Solutions for "Pawn Brotherhood" solution in Uncategorized category for Pawn Brotherhood by kaisa.kucherenko
def safe_pawns(pawns: set) -> int:
""" The function checks if the pawn is protected.
the input data is divided into a list of tuples (tmp_lst),
so that you can take the letter and number by index.
Run for by tmp_lst
1. Take the number and subtract 1
int (p [1]) - 1)
so we check if there are pawn lower on the line
2. Next, we take the letter from the tuple p[0]
looking for her in letters
and take the letter to the left of it and to the right by index
letters [letters.index (p [0]) - 1]
letters [letters.index (p [0]) + 1]
3. .join of this found letter in paragraph 2 and the number
found in paragraph 1 in str and find it in pawns
if there is, then result + = 1
P.S .: In letters, we add an empty line to the left and right,
so that there are no index errors when we
are given 'a' and 'h' in the input
"""
letters = ['','a','b','c','d','e','f','g','h', '']
result = 0
tmp_lst = [tuple(p) for p in pawns]
for p in tmp_lst:
if ''.join([letters[letters.index(p[0])-1], str(int(p[1])-1)]) in pawns:
result += 1
elif ''.join([letters[letters.index(p[0])+1], str(int(p[1]) - 1)]) in pawns:
result += 1
return result
May 29, 2020
Forum
Price
Global Activity
ClassRoom Manager
Leaderboard
Coding games
Python programming for beginners