(y, x, get_cell)
| 88 | |
| 89 | print("Example 4") |
| 90 | def count_neighbors(y, x, get_cell): |
| 91 | n_ = get_cell(y - 1, x + 0) # North |
| 92 | ne = get_cell(y - 1, x + 1) # Northeast |
| 93 | e_ = get_cell(y + 0, x + 1) # East |
| 94 | se = get_cell(y + 1, x + 1) # Southeast |
| 95 | s_ = get_cell(y + 1, x + 0) # South |
| 96 | sw = get_cell(y + 1, x - 1) # Southwest |
| 97 | w_ = get_cell(y + 0, x - 1) # West |
| 98 | nw = get_cell(y - 1, x - 1) # Northwest |
| 99 | neighbor_states = [n_, ne, e_, se, s_, sw, w_, nw] |
| 100 | count = 0 |
| 101 | for state in neighbor_states: |
| 102 | if state == ALIVE: |
| 103 | count += 1 |
| 104 | return count |
| 105 | |
| 106 | |
| 107 | alive = {(9, 5), (9, 6)} |
no outgoing calls
no test coverage detected