Update neighbors cells
Propation is right for small iteration and/or pile with low grain rate. For pile with high grain rate, the main while loop is not enough to make propagation in all cells
This commit is contained in:
parent
eebd2751fe
commit
2119783dad
|
@ -36,10 +36,10 @@ def main(pile, n):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
size = len(pile)
|
size = len(pile)
|
||||||
|
x_max, y_max = size - 1, size - 1
|
||||||
center = int((size - 1) / 2)
|
center = int((size - 1) / 2)
|
||||||
|
|
||||||
while n != 0:
|
while n != 0:
|
||||||
|
|
||||||
pile[center][center] += 1
|
pile[center][center] += 1
|
||||||
|
|
||||||
# find cells > 3
|
# find cells > 3
|
||||||
|
@ -50,6 +50,19 @@ def main(pile, n):
|
||||||
if pile[x][y] > 3:
|
if pile[x][y] > 3:
|
||||||
pile[x][y] -= 4
|
pile[x][y] -= 4
|
||||||
|
|
||||||
|
# update west neighbor
|
||||||
|
if x < x_max:
|
||||||
|
pile[x + 1][y] += 1
|
||||||
|
# update east neighbor
|
||||||
|
if x > 0:
|
||||||
|
pile[x - 1][y] += 1
|
||||||
|
# update north neighbor
|
||||||
|
if y < y_max:
|
||||||
|
pile[x][y + 1] += 1
|
||||||
|
# update south neighbor
|
||||||
|
if y > 0:
|
||||||
|
pile[x][y - 1] += 1
|
||||||
|
|
||||||
n -= 1
|
n -= 1
|
||||||
|
|
||||||
return pile
|
return pile
|
||||||
|
|
Loading…
Reference in New Issue