| Total Complexity | 8 |
| Total Lines | 29 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | def possible_neighbor(pawn): |
||
| 2 | # find neighbors can suppor itself |
||
| 3 | col, row = list(pawn) |
||
| 4 | result = [] |
||
| 5 | if int(row) > 1: |
||
| 6 | row = str(int(pawn[1]) - 1) |
||
| 7 | if col < 'h': |
||
| 8 | result.append(chr(ord(col) + 1) + row) |
||
| 9 | if col > 'a': |
||
| 10 | result.append(chr(ord(col) - 1) + row) |
||
| 11 | return result |
||
| 12 | |||
| 13 | |||
| 14 | def safe_pawns(pawns): |
||
| 15 | safe_counter = 0 |
||
| 16 | for i in pawns: |
||
| 17 | for j in possible_neighbor(i): |
||
| 18 | if j in pawns: |
||
| 19 | safe_counter += 1 |
||
| 20 | break |
||
| 21 | return safe_counter |
||
| 22 | |||
| 23 | |||
| 24 | if __name__ == '__main__': # pragma: no cover |
||
| 25 | # These "asserts" using only for self-checking and not necessary for |
||
| 26 | # auto-testing |
||
| 27 | assert safe_pawns({"b4", "d4", "f4", "c3", "e3", "g5", "d2"}) == 6 |
||
| 28 | assert safe_pawns({"b4", "c4", "d4", "e4", "f4", "g4", "e5"}) == 1 |
||
| 29 |