Day 08
This commit is contained in:
26
day08/part2.py
Normal file
26
day08/part2.py
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python3
|
||||
import math
|
||||
from itertools import count, takewhile
|
||||
|
||||
import numpy as np
|
||||
|
||||
forest = np.array([np.array(list(map(int, x.strip()))) for x in open("input.txt")])
|
||||
|
||||
max_score = 0
|
||||
for y in range(len(forest)):
|
||||
for x in range(len(forest[0])):
|
||||
score = 1
|
||||
for dir in np.array([(0, -1), (0, 1), (-1, 0), (1, 0)]):
|
||||
pos = np.array([y, x]) + dir
|
||||
dir_score = 0
|
||||
for i in takewhile(lambda _: np.all(pos >= 0) and np.all(pos < forest.shape), count()):
|
||||
dir_score += 1
|
||||
if forest[tuple(pos)] >= forest[y, x]:
|
||||
break
|
||||
pos += dir
|
||||
score *= dir_score
|
||||
max_score = max(max_score, score)
|
||||
print(max_score)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user