Skip to content

Commit f35415e

Browse files
committed
By Zhao Kun Peng
1 parent 5b0c95e commit f35415e

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

checkio/pawns.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def safe_pawns(pawns: set) -> int:
2+
t=[]
3+
s=filter(judge,pawns)
4+
for i in s:
5+
if chr(ord(i[0])+1)+str(int(i[1])-1) in pawns:
6+
t.append(i)
7+
elif chr(ord(i[0])-1)+str(int(i[1])-1) in pawns:
8+
t.append(i)
9+
return len(t)
10+
def judge(n):
11+
if int(n[1]) == 1:
12+
return False
13+
return True
14+
if __name__ == '__main__':
15+
#These "asserts" using only for self-checking and not necessary for auto-testing
16+
assert safe_pawns({"b4", "d4", "f4", "c3", "e3", "g5", "d2"}) == 6
17+
assert safe_pawns({"b4", "c4", "d4", "e4", "f4", "g4", "e5"}) == 1
18+
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")

0 commit comments

Comments
 (0)