Created
September 30, 2014 13:09
-
-
Save juanplopes/a981f73deaf4068c3b52 to your computer and use it in GitHub Desktop.
Simple scheduling algorithm in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import heapq | |
def schedule(tasks): | |
heap = [] | |
def offer(begin, end): | |
while heap and heap[0] <= begin: | |
heapq.heappop(heap) | |
heapq.heappush(heap, end) | |
return len(heap) | |
return max(offer(begin, end) for begin, end in sorted(tasks)) | |
print schedule([(12,13), (13,15), (17,20), (13,14), (19, 21), (18, 20)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment