feat: Initial commit

This commit is contained in:
2024-03-22 17:01:42 +01:00
parent 954985f39a
commit c343ff6e93
106 changed files with 143428 additions and 1 deletions

View File

@@ -0,0 +1,55 @@
from sys import exit
def carica_piramide(filename: str):
try:
fio = open(filename, "r")
except FileNotFoundError:
exit(f"Attenzione! {filename} non trovato")
mappa = []
for i in fio:
righa = [int(c) for c in i.strip().split()]
mappa.append(righa)
fio.close()
return mappa
def lista_adiacenti(mappa: list, x: int, y: int):
items = []
for a in range(max(0, x - 1), min(x + 2, len(mappa))):
for b in range(max(0, y - 1), min(y + 2, len(mappa[x]))):
if a == x and b == y:
continue
items.append(mappa[a][b])
return items
def cerca_piramidi(mappa: list):
somma_altezze = 0
numero_piramidi = 0
for x in range(len(mappa)):
for y in range(len(mappa[x])):
altezza_massima = max(lista_adiacenti(mappa, x, y))
if mappa[x][y] > altezza_massima:
print(mappa[x][y], x, y)
somma_altezze += mappa[x][y]
numero_piramidi += 1
return somma_altezze / numero_piramidi
def main():
mappa = carica_piramide("mappa.txt")
media = cerca_piramidi(mappa)
print(f"Altezza media: {media} m")
main()

View File

@@ -0,0 +1,10 @@
3 4 4 4 3 2 1 0 0 0
3 4 5 4 3 2 1 1 1 1
3 4 4 4 3 2 2 2 2 1
3 3 3 3 3 3 3 3 2 1
2 2 2 2 2 3 4 3 2 1
1 1 1 1 2 3 3 3 2 1
0 0 0 1 2 2 2 2 2 1
0 0 0 1 1 1 1 1 1 1
0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0