Skip to content

Commit 124c12b

Browse files
Super Computer
1 parent 6635751 commit 124c12b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

puzzles/python3/super-computer/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,23 @@ To solve this problem, you need to find the maximum number of non-overlapping ca
5454
5. Output the count of performed calculations as the maximum number of calculations that can be carried out without overlapping.
5555

5656
This algorithm ensures that calculations are scheduled in a way that maximizes the usage of the supercomputer without overlapping reservation periods.
57+
58+
## Example Code
59+
60+
```python
61+
# Sort the calculations
62+
calculations.sort(key=lambda x: x[1])
63+
64+
# Initialize variables
65+
max_calculations = 0
66+
selected_calculations = []
67+
68+
# Greedy algorithm
69+
for calculation in calculations:
70+
if not selected_calculations:
71+
selected_calculations.append(calculation)
72+
max_calculations += 1
73+
elif calculation[0] > selected_calculations[-1][1]:
74+
selected_calculations.append(calculation)
75+
max_calculations += 1
76+
```

0 commit comments

Comments
 (0)