From bfcffc614c8782804a2f6ec139760b8a3248d350 Mon Sep 17 00:00:00 2001 From: Andrew Ekstedt Date: Thu, 8 Dec 2022 22:34:03 -0800 Subject: [PATCH] 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 --- day08/sol2b.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 day08/sol2b.py diff --git a/day08/sol2b.py b/day08/sol2b.py new file mode 100644 index 0000000..cab0b94 --- /dev/null +++ b/day08/sol2b.py @@ -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))