From d38e9fa85bab9bd0b6dc38bf477825bbe4630b78 Mon Sep 17 00:00:00 2001 From: kwout Date: Sat, 11 Feb 2023 11:16:46 -0500 Subject: [PATCH] solved 9b in 9a --- .gitignore | 1 + 2021/day9/9a.py | 24 +++++++++++++++++++++++- README.md | 4 ++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 71f62e4..495c2fb 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ *.swp *.swo +.DS_Store diff --git a/2021/day9/9a.py b/2021/day9/9a.py index 23a1a8b..b61b2cc 100644 --- a/2021/day9/9a.py +++ b/2021/day9/9a.py @@ -18,4 +18,26 @@ for p in lowList: print(summa) -print(lowList) +explored = [] + +def explore(x,y): + if lines[x][y] == 9 or (x,y) in explored: + return 0 + explored.append((x,y)) + size = 1 + if y != 0: + size += explore(x,y-1) + if y != len(lines[x]) - 1: + size += explore(x,y+1) + if x != 0: + size += explore(x-1,y) + if x != len(lines) - 1: + size += explore(x+1,y) + return size + +sizes = [0]*len(lowList) +for i in range(len(lowList)): + sizes[i] = explore(lowList[i][0],lowList[i][1]) + +sizes.sort() +print(sizes[-1] * sizes[-2] * sizes[-3]) \ No newline at end of file diff --git a/README.md b/README.md index b6730b1..28a344d 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ my solutions for the [Advent of Code](https://adventofcode.com/) in progress:\ -2021 (python) -2022 (python) +2021 (python)\ planned:\ +2022 (rust)\ 2020\ 2019\ 2018\