From 5357c5da191fe96da5f9b07448023bc183c362c8 Mon Sep 17 00:00:00 2001 From: kwout Date: Sat, 11 Feb 2023 13:46:54 -0500 Subject: [PATCH] solved 11a --- 2021/day11/11.py | 32 ++++++++++++++++++++++++++++++++ 2021/day11/input.txt.sample | 10 ++++++++++ 2 files changed, 42 insertions(+) create mode 100644 2021/day11/11.py create mode 100644 2021/day11/input.txt.sample diff --git a/2021/day11/11.py b/2021/day11/11.py new file mode 100644 index 0000000..b8dc80c --- /dev/null +++ b/2021/day11/11.py @@ -0,0 +1,32 @@ +lines = [ [int(j) for j in list(i)] for i in open("input.txt", 'r').read().splitlines()] + +flashes = 0 +for i in range(100): + lines = [ [x+1 for x in y] for y in lines] + flashed = True + while flashed: + flashed = False + for x in range(10): + for y in range(10): + if lines[x][y] > 9: + flashes += 1 + lines[x][y] = 0 + flashed = True + if x != 0 and lines[x-1][y] != 0: + lines[x-1][y] += 1 + if x != 0 and y != 9 and lines[x-1][y+1] != 0: + lines[x-1][y+1] += 1 + if y != 9 and lines[x][y+1] != 0: + lines[x][y+1] += 1 + if x != 9 and y != 9 and lines[x+1][y+1] != 0: + lines[x+1][y+1] += 1 + if x != 9 and lines[x+1][y] != 0: + lines[x+1][y] += 1 + if x != 9 and y != 0 and lines[x+1][y-1] != 0: + lines[x+1][y-1] += 1 + if y != 0 and lines[x][y-1] != 0: + lines[x][y-1] += 1 + if x != 0 and y != 0 and lines[x-1][y-1] != 0: + lines[x-1][y-1] += 1 + +print(flashes) \ No newline at end of file diff --git a/2021/day11/input.txt.sample b/2021/day11/input.txt.sample new file mode 100644 index 0000000..a3819c9 --- /dev/null +++ b/2021/day11/input.txt.sample @@ -0,0 +1,10 @@ +5483143223 +2745854711 +5264556173 +6141336146 +6357385478 +4167524645 +2176841721 +6882881134 +4846848554 +5283751526 \ No newline at end of file