Created
December 8, 2022 20:14
-
-
Save eduardoklosowski/b1a5cf3a46645c6cda5de603f4ded9a0 to your computer and use it in GitHub Desktop.
Advent of Code 2022 - Dia 08
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
entrada = [[int(b) for b in a.rstrip()] for a in open('8/input')] | |
visivel = set() | |
for i in range(len(entrada)): | |
m = -1 | |
for j in range(len(entrada[i])): | |
a = entrada[i][j] | |
if a > m: | |
visivel.add((i, j)) | |
m = a | |
if m == 9: | |
break | |
m = -1 | |
for j in reversed(range(len(entrada[i]))): | |
a = entrada[i][j] | |
if a > m: | |
visivel.add((i, j)) | |
m = a | |
if m == 9: | |
break | |
for j in range(len(entrada[0])): | |
m = -1 | |
for i in range(len(entrada)): | |
a = entrada[i][j] | |
if a > m: | |
visivel.add((i, j)) | |
m = a | |
if m == 9: | |
break | |
m = -1 | |
for i in reversed(range(len(entrada))): | |
a = entrada[i][j] | |
if a > m: | |
visivel.add((i, j)) | |
m = a | |
if m == 9: | |
break | |
print(len(visivel)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
entrada = [[int(b) for b in a.rstrip()] for a in open('8/input')] | |
visibilidade_max = 0 | |
for i in range(len(entrada)): | |
for j in range(len(entrada[i])): | |
a = entrada[i][j] | |
cima = 0 | |
for k in reversed(range(0, i)): | |
cima += 1 | |
if entrada[k][j] >= a: | |
break | |
baixo = 0 | |
for k in range(i + 1, len(entrada)): | |
baixo += 1 | |
if entrada[k][j] >= a: | |
break | |
esquerda = 0 | |
for k in reversed(range(0, j)): | |
esquerda += 1 | |
if entrada[i][k] >= a: | |
break | |
direita = 0 | |
for k in range(j + 1, len(entrada[i])): | |
direita += 1 | |
if entrada[i][k] >= a: | |
break | |
visibilidade = cima * baixo * esquerda * direita | |
if visibilidade > visibilidade_max: | |
visibilidade_max = visibilidade | |
print(visibilidade_max) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment