+/AoC
advent of code
git clone https://git.julia.blue/+/AoC
a7718a0
master
1from operator import mul 2from functools import reduce 3from itertools import product 4 5 6def seen (l ,n ):# TODO: "takewhile" + 1? 7viz = 0 8for x in l : 9viz += 1 10if x >= n : 11break 12return viz 13 14 15grid = [[int (x )for x in line .strip ()]for line in open ("input" )] 16size = len (grid ) 17trans = [[grid [x ][y ]for x in range (size )]for y in range (size )] 18total = size * 4 - 4 19maxviz = 0 20neighbors = lambda x ,y : ( 21grid [x ][:y ][::- 1 ], 22grid [x ][y + 1 :], 23trans [y ][:x ][::- 1 ], 24trans [y ][x + 1 :], 25) 26 27for x ,y in product (range (1 ,size - 1 ),repeat = 2 ): 28a = grid [x ][y ] 29adj = neighbors (x ,y ) 30total += any (max (n )< a for n in adj ) 31maxviz = max (maxviz ,reduce (mul , (seen (n ,a )for n in adj ))) 32 33 34total ) 35maxviz )