Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Make your move wisely !!! solution in Clear category for Pawn Brotherhood by ChromeBrainer
def safe_pawns(pawns: set) -> int:
#8
#7
#6
#5 |
#4 | | |
#3 | |
#2 |
#1
# a b c d e f g h
l=[]
for i,j in enumerate(pawns):
if (chr(ord(j[0])+1)+chr(ord(j[1])+1) in pawns):
l.append(chr(ord(j[0])+1)+chr(ord(j[1])+1))
if (chr(ord(j[0])-1)+chr(ord(j[1])+1) in pawns):
l.append(chr(ord(j[0])-1)+chr(ord(j[1])+1))
if (j[1] == '8'):
if (chr(ord(j[0])+1)+chr(ord(j[1])-1) in pawns):
l.append(chr(ord(j[0])+1)+chr(ord(j[1])-1))
if (chr(ord(j[0])-1)+chr(ord(j[1])-1) in pawns):
l.append(chr(ord(j[0])-1)+chr(ord(j[1])-1))
# g5 b4,d4 d4,f4 c3,e3
#[a5,c5 c5,e5 e5, f6,h6
return len(set(l))
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
safe_pawns({"b4", "d4", "f4", "c3", "e3", "g5", "d2"})
safe_pawns(["a1","b2","c3","d4","e5","f6","g7","h8"])
safe_pawns(["a1","b2","c3","d4","e5","f6","g7","h8"])
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!")
May 10, 2021
Comments: