From 9a6368abb9170fac06e2c92adeca450d11c0363c Mon Sep 17 00:00:00 2001 From: kwout Date: Wed, 6 Dec 2023 14:07:09 -0500 Subject: [PATCH] 2022 day 8 part 1 solved --- 2022/8.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 2022/8.py diff --git a/2022/8.py b/2022/8.py new file mode 100644 index 0000000..b0d8b98 --- /dev/null +++ b/2022/8.py @@ -0,0 +1,27 @@ +matrix = [[int(i) for i in j] for j in open("input2.txt", 'r').read().splitlines()] +visible = set() + +def walk(line): + length = len(line) + vis = [0, length-1] + tallest = line[0] + tallestInv = line[-1] + for i in range(1, length): + if line[i] > tallest: + vis.append(i) + tallest = line[i] + if line[length-i] > tallestInv: + vis.append(length-i) + tallestInv = line[-i] + print(vis) + return vis + +for i in range(len(matrix)): + for coord in walk(matrix[i]): + visible.add((i, coord)) +for i in range(len(matrix[0])): + for coord in walk([matrix[j][i] for j in range(len(matrix[0]))]): + visible.add((coord, i)) + +print(visible) +print(len(visible)) \ No newline at end of file