From eebd2751fe513e093b4b1666ecb59a0bfa11c75d Mon Sep 17 00:00:00 2001 From: Freezed Date: Thu, 16 Jul 2020 11:19:41 +0200 Subject: [PATCH] Update only drop cell Structure for pile walking to find cells greater than 3 is set I do not update neighbors cells, then only central value of the pile (where the sand grain is dropped) is at the right value in the end --- technical_tests/sand_grain_drop.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/technical_tests/sand_grain_drop.py b/technical_tests/sand_grain_drop.py index 82bf1d3..7c774f6 100644 --- a/technical_tests/sand_grain_drop.py +++ b/technical_tests/sand_grain_drop.py @@ -35,11 +35,21 @@ def main(pile, n): [[0, 1, 0, 1, 0], [1, 2, 2, 2, 1], [0, 2, 0, 2, 0], [1, 2, 2, 2, 1], [0, 1, 0, 1, 0]] """ - center = int((len(pile) - 1) / 2) + size = len(pile) + center = int((size - 1) / 2) while n != 0: pile[center][center] += 1 + + # find cells > 3 + for x in range(size): + + for y in range(size): + + if pile[x][y] > 3: + pile[x][y] -= 4 + n -= 1 return pile