MCPcopy Create free account
hub / github.com/bslatkin/effectivepython / count_neighbors

Function count_neighbors

example_code/item_073.py:143–157  ·  view source on GitHub ↗
(y, x, get_cell)

Source from the content-addressed store, hash-verified

141
142
143def count_neighbors(y, x, get_cell):
144 n_ = get_cell(y - 1, x + 0) # North
145 ne = get_cell(y - 1, x + 1) # Northeast
146 e_ = get_cell(y + 0, x + 1) # East
147 se = get_cell(y + 1, x + 1) # Southeast
148 s_ = get_cell(y + 1, x + 0) # South
149 sw = get_cell(y + 1, x - 1) # Southwest
150 w_ = get_cell(y + 0, x - 1) # West
151 nw = get_cell(y - 1, x - 1) # Northwest
152 neighbor_states = [n_, ne, e_, se, s_, sw, w_, nw]
153 count = 0
154 for state in neighbor_states:
155 if state == ALIVE:
156 count += 1
157 return count
158
159def simulate_pipeline(grid, in_queue, out_queue):
160 for y in range(grid.height):

Callers 2

simulate_pipelineFunction · 0.70
count_neighbors_threadFunction · 0.70

Calls 1

recvMethod · 0.80

Tested by

no test coverage detected