-
Notifications
You must be signed in to change notification settings - Fork 0
/
avg.py
56 lines (44 loc) · 1.07 KB
/
avg.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
n=int(input('Enter the number of nodes:- '))
l=[]
print('\nPlease enter time in HH:MM format.\nEnter the time for:-')
for i in range(n):
print("Node",i+1,": ",end='')
l.append(input())
s=input('\nEnter the agreed upon time (in HH:MM format):- ')
time=s[:3]
s=int(s[3:])
l1=[]
for i in l:
l1.append(int(i[3:]))
l2=l1.copy()
l2.sort(reverse=True)
print('\n')
a=['']*n
for i in range(n):
print('Iteration',i+1,':')
for j in range(n):
if(l1[j]==l2[i]):
break
print('Message is sent by node',chr(ord('a')+j),'.')
temp=[]
t=0
for k in range(n):
t+=(l1[k]-s)
temp.append(abs(l1[k]-s))
temp.remove(0)
temp.sort()
print('Interval time:',temp[0],' minutes.')
for k in range(n):
l1[k]+=temp[0]
l2[k]+=temp[0]
t/=n
print('Average computed =',t,' minutes.\n')
if(t<0):
aob='behind'
else:
aob='ahead'
a[j]='Node '+str(chr(ord('a')+j))+' moves '+aob+ ' by '+str(abs(t))+' minutes.'
for i in range(n):
l1[i]-=temp[0]
print(a[i])
print('\nThe SYNCHRONIZED TIME is: ',time+str(l1[j]+t),' minutes.')