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 outmain
parent
a3e4290ccd
commit
bfcffc614c
|
@ -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))
|
Loading…
Reference in New Issue