From c9314ad089256f390fbe04e0df674e03c91ba09a Mon Sep 17 00:00:00 2001 From: Mika Suhonen Date: Thu, 8 Dec 2022 11:20:50 +0200 Subject: [PATCH] day 8 first answer --- 08/h.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 08/h.py diff --git a/08/h.py b/08/h.py new file mode 100644 index 0000000..336fb6c --- /dev/null +++ b/08/h.py @@ -0,0 +1,55 @@ +import os + +input = open(os.path.dirname(__file__) + + "/input.txt", "r").readlines() + +trees = [] + +for l in input: + l = l.strip() + tmp = [] + for x in l: + tmp.append([int(x), False]) + trees.append(tmp) + +height_ = len(trees) +width = len(trees[0]) + +# for x in range(0, height_, 1): +# print(trees[x]) + +for x in range(0, width, 1): + height = 0 + for y in range(0, width, 1): + if trees[x][y][0] > height or (x == 0) or (y == 0) or (x == width-1) or (y == height_-1): + trees[x][y][1] = True + height = trees[x][y][0] + + height = 0 + for y in range(width-1, -1, -1): + if trees[x][y][0] > height or (x == 0) or (y == 0) or (x == width-1) or (y == height_-1): + trees[x][y][1] = True + height = trees[x][y][0] + + +for y in range(0, height_, 1): + height = 0 + for x in range(0, height_, 1): + if trees[x][y][0] > height or (x == 0) or (y == 0) or (x == width-1) or (y == height_-1): + trees[x][y][1] = True + height = trees[x][y][0] + + height = 0 + for x in range(height_-1, -1, -1): + if trees[x][y][0] > height or (x == 0) or (y == 0) or (x == width-1) or (y == height_-1): + trees[x][y][1] = True + height = trees[x][y][0] + +tot = 0 +for x in range(0, height_, 1): + # print(trees[x]) + for y in range(0, width, 1): + if trees[x][y][1]: + tot += 1 + +print(tot)