forked from hardikagarwal2001/Hackoctober
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort.py
More file actions
38 lines (26 loc) · 613 Bytes
/
sort.py
File metadata and controls
38 lines (26 loc) · 613 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
33
34
35
36
37
38
# Python implementation of the
# above approach
from heapq import heappop, heappush, heapify
# Function to find the optimum sequence
def optimum_sequence_jobs(V: list, P: float):
N = len(V) - 1
j = 1
result = 0
Queue = []
for i in V[1:]:
heappush(Queue, i)
while Queue:
top = heappop(Queue)
V[j] = top
print(top, end=" ")
j += 1
print()
# Calculationg with decay
for i in range(N, 0, -1):
result += V[i] * pow((1 - P), (N - i))
print(f"{result:.4f}")
if __name__ == "__main__":
V = [-1, 3, 5, 4, 1, 2, 7, 6, 8, 9, 10]
# 10% loss per day
P = 0.10
optimum_sequence_jobs(V, P)