-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday14.py
More file actions
32 lines (23 loc) · 977 Bytes
/
day14.py
File metadata and controls
32 lines (23 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
Complete the Difference class by writing the following:
- A class constructor that takes an array of integers as a parameter and saves it to the elements instance variable.
- A computeDifference method that finds the maximum absolute difference between any numbers in and stores it in the instance variable.
"""
class Difference:
def __init__(self, a):
self.__elements = a
# Two loop cycles that check abs diference between elements and keep the max
def computeDifference(self):
max_value = 0
for i in range(len(self.__elements)):
for j in range(i+1, len(self.__elements)):
result = abs(self.__elements[i]-self.__elements[j])
if result > max_value:
max_value = result
self.maximumDifference = max_value
# End of Difference class
_ = input()
a = [int(e) for e in input().split(' ')]
d = Difference(a)
d.computeDifference()
print(d.maximumDifference)