day 8 part 2 alternate python solution

although it's shorter, i'm not sure if i like the way the count function
was factored out
main
magical 2022-12-08 22:34:03 -08:00
parent a3e4290ccd
commit bfcffc614c
1 changed files with 29 additions and 0 deletions

29
day08/sol2b.py 100644
View File

@ -0,0 +1,29 @@
data = []
for line in open("input"):
data.append(list(map(int, line.strip())))
def count(top, ii, jj):
n = 0
for i in ii:
for j in jj:
n += 1
if data[i][j] >= top:
return n
return n
scores = []
for ii in range(len(data)):
for jj in range(len(data[ii])):
top = data[ii][jj]
a = count(top, [ii], range(jj+1, len(data[ii])))
b = count(top, [ii], reversed(range(0, jj)))
c = count(top, range(ii+1, len(data)), [jj])
d = count(top, reversed(range(0, ii)), [jj])
#print(ii,jj,a,b,c,d)
score = a*b*c*d
scores.append(score)
#print(visible)
#print(sum(sum(x) for x in visible))
print(max(scores))