Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Pawn Brotherhood by Steven2222
def safe_pawns(pawns: set) -> int:
""" Checks pawn safety state in one sided
configuration of pawns.
In: set of strings
Out: int """
# letter of element to ascii code, number to int
# Calculate left and right position on lower row
# Check if occupied
safe = 0
for element in pawns:
#print('element is ' + str(element))
letter = element[0]
number = element[1]
for i in (0, 2):
#print(i)
target = chr(ord(letter)-1+i)+str(int(number)-1)
#print(target)
if target in pawns:
safe += 1
#print (safe)
break
#print ('Dit is ' + str(safe))
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!")
April 13, 2021
Comments: