feat: Initial commit
This commit is contained in:
27
Laboratorio8/esercizio1.py
Normal file
27
Laboratorio8/esercizio1.py
Normal file
@@ -0,0 +1,27 @@
|
||||
def removeDup(a):
|
||||
i=0
|
||||
while i < len(a) - 1:
|
||||
if a[i] == a[i + 1]:
|
||||
a.pop(i)
|
||||
else:
|
||||
i += 1
|
||||
|
||||
|
||||
def sameElements(a, b):
|
||||
cpa = sorted(a)
|
||||
cpb = sorted(b)
|
||||
|
||||
if len(cpa) == len(cpb):
|
||||
i=0
|
||||
while i < len(cpa):
|
||||
if cpa[i] != cpb[i]:
|
||||
break
|
||||
|
||||
i += 1
|
||||
|
||||
if i == len(cpa):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
print(sameElements([1,5,2,4,8], [1,4,2,8,5]))
|
||||
21
Laboratorio8/esercizio2.py
Normal file
21
Laboratorio8/esercizio2.py
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
def retNumOrZero(values, row, column):
|
||||
if 0 > row or row >= len(values) or 0 > column or row >= len(values[0]):
|
||||
return None
|
||||
|
||||
return values[row][column]
|
||||
|
||||
def neighborAverage(values, row, column):
|
||||
nums = [retNumOrZero(values, row - 1, column - 1), retNumOrZero(values, row - 1, column), retNumOrZero(values, row - 1, column + 1), retNumOrZero(values, row, column - 1), retNumOrZero(values, row, column), retNumOrZero(values, row, column + 1), retNumOrZero(values, row + 1, column - 1), retNumOrZero(values, row + 1, column), retNumOrZero(values, row + 1, column + 1)]
|
||||
su = 0
|
||||
d = 0
|
||||
for n in nums:
|
||||
if n is not None:
|
||||
su += n
|
||||
d += 1
|
||||
|
||||
print(su / d, end="\t")
|
||||
|
||||
a = [[0,1,2],[3,4,5],[6,7,8]]
|
||||
|
||||
neighborAverage(a, 0, 0)
|
||||
0
Laboratorio8/esercizio3.py
Normal file
0
Laboratorio8/esercizio3.py
Normal file
Reference in New Issue
Block a user