From 9d314c20bc70ce476d7d738d9bf7f1642320eaa8 Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Mon, 30 Sep 2024 10:28:07 +0200 Subject: [PATCH] 8-2 --- 8/twostar.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 8/twostar.py diff --git a/8/twostar.py b/8/twostar.py new file mode 100644 index 0000000..a1d8f95 --- /dev/null +++ b/8/twostar.py @@ -0,0 +1,32 @@ +map = [] +def directionScore(x, y, tree): + score = 0 + if type(x) == range: # Horizontal + for i in x: + score += 1 + if map[y][i] >= tree: + break + elif type(y) == range: # Vertical + for i in y: + score += 1 + if map[i][x] >= tree: + break + return score + +with open("input.txt", "r") as f: + for line in f.readlines(): + map.append(list(line.strip())) +H = len(map) +W = len(map[0]) + +biggestScore = 0 +for y in range(H): + for x in range(W): + tree = map[y][x] + score = (directionScore(x, range(y-1, -1, -1), tree) * # Up + directionScore(x, range(y+1, H), tree) * # Down + directionScore(range(x-1, -1, -1), y, tree) * # Left + directionScore(range(x+1, W), y, tree)) # Right + if score > biggestScore: + biggestScore = score +print(biggestScore) \ No newline at end of file