rj1
about | log | files | refs
commit dde65672a4dd12c30ec5fcddfd4044e31782ff77
parent 57b33553b32cbeab0c09af33a6f38fa55227dd12
author: rj1 <[email protected]>
date:   Thu,  8 Dec 2022 12:40:53 -0600

day 8 solution

Diffstat:
A2022/08/solution.py | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MREADME.md | 2++
2 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/2022/08/solution.py b/2022/08/solution.py @@ -0,0 +1,60 @@ +import os + +base_dir = os.path.realpath(os.path.dirname(__file__)) +with open(base_dir + "/input.txt", "r") as file: + input = file.read().rstrip() + +lines = input.split("\n") + + +grid = [] +for line in lines: + grid.append(line) + +rows = len(grid) +cols = len(grid[0]) +org = [(-1, 0), (0, 1), (1, 0), (0, -1)] + +part1 = 0 +for row in range(rows): + for c in range(cols): + visible = False + for (dorow, docol) in org: + rowf = row + colf = c + ok = True + while True: + rowf += dorow + colf += docol + if not (0 <= rowf < rows and 0 <= colf < cols): + break + if grid[rowf][colf] >= grid[row][c]: + ok = False + if ok: + visible = True + if visible: + part1 += 1 + +print(part1) + +part2 = 0 +for row in range(rows): + for c in range(cols): + total = 1 + for (dorow, docol) in org: + distance = 1 + rowf = row + dorow + colf = c + docol + while True: + if not (0 <= rowf < rows and 0 <= colf < cols): + distance -= 1 + break + if grid[rowf][colf] >= grid[row][c]: + break + distance += 1 + rowf += dorow + colf += docol + total *= distance + part2 = max(part2, total) + +print(part2) diff --git a/README.md b/README.md @@ -14,6 +14,7 @@ this repo contains my solutions for advent of code |5|00:17:50|2168|0| |6|00:08:15|4815|0| |7|00:19:50|735|0| +|8|13:04:24|52832|0| ### part 2 @@ -26,6 +27,7 @@ this repo contains my solutions for advent of code |5|12:38:15|61014|0| |6|00:08:47|3739|0| |7|00:26:28|871|0| +|8|13:31:01|46137|0| ## notes