Comments (1)
def select_activities(set_of_activities):
activities=list(set_of_activities)
activities.sort()
activities=list(enumerate(activities))
lastend=0
for index, activity in activities:
if activity[0]<activity[1]:
if activity[0]<lastend:
activities[index]=(index,"DEL")
else:
lastend=activity[1]
else:
activities[index] = (index, "DEL")
result=[activity for index, activity in activities if activity!='DEL']
return result
def test_select_activities(set_of_activities, expected):
result=select_activities(set_of_activities)
return result==expected
# TEST CASES:
activities={(6, 8), (7, 9), (9, 13), (14, 18), (15, 17), (18, 20), (20, 24), (21, 23), (20, 23), (23,24)}
expected=[(6, 8), (9, 13), (14, 18), (18, 20), (20, 23), (23, 24)]
print (test_select_activities(activities, expected))
activities={(1, 4), (3, 5), (4, 6), (6, 9), (9, 12), (11, 13), (16, 18), (17, 19), (18, 22), (21,24)}
expected=[(1, 4), (4, 6), (6, 9), (9, 12), (16, 18), (18, 22)]
print (test_select_activities(activities, expected))
activities={(22, 24), (7, 9), (16, 20), (16, 22), (13, 17), (11, 14), (20, 22)}
expected=[(7, 9), (11, 14), (16, 20), (20, 22), (22, 24)]
print (test_select_activities(activities, expected))
activities={(24, 22), (7, 9), (16, 20), (16, 22), (13, 17), (11, 14), (20, 22)}
expected=[(7, 9), (11, 14), (16, 20), (20, 22)]
print (test_select_activities(activities, expected))
from 2020-2021.
Related Issues (20)
- Lecture "Brute-force algorithms", exercise 5 HOT 15
- Lecture "Organising information: unordered structures", exercise 1 HOT 21
- Lecture "Organising information: unordered structures", exercise 2 HOT 19
- Lecture "Organising information: unordered structures", exercise 3 HOT 20
- Lecture "Recursion", exercise 1 HOT 19
- Lecture "Recursion", exercise 2 HOT 20
- Lecture "Divide and conquer algorithms", exercise 1 HOT 19
- Lecture "Divide and conquer algorithms", exercise 2 HOT 17
- Lecture "Divide and conquer algorithms", exercise 3 HOT 5
- Lecture "Dynamic programming algorithms", exercise 1 HOT 21
- Lecture "Dynamic programming algorithms", exercise 2 HOT 19
- Lecture "Organising information: trees", exercise 1 HOT 9
- Lecture "Organising information: trees", exercise 2 HOT 7
- Bonus exercise (AtariGo) HOT 2
- Lecture "Backtracking algorithms", exercise 1 HOT 6
- Lecture "Backtracking algorithms", exercise 2 HOT 5
- Lecture "Organising information: graphs", exercise 1 HOT 15
- Lecture "Organising information: graphs", exercise 2 HOT 14
- Lecture "Greedy algorithms", exercise 1 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from 2020-2021.