Skip to content

Instantly share code, notes, and snippets.

Created February 16, 2020 22:24
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
def final_time(tasks, cooldown):
# this question is actually about putting a serialized tasks into parallel task Q
task_run_time = 1
lastExcStart = {} # coreId:lastTask's Start Time
sim_time = 0
for task in tasks:
if task not in lastExcStart:
# if no task is running on this core, init the queue with cuurent simTime
lastExcStart[task] = sim_time
# if this core had a task. propergate the simTime using the cooldown constrict
if sim_time - lastExcStart[task] >= task_run_time + cooldown:
# if the sim time gap is larger than a cooldown, then you can start this task right away
lastExcStart[task] = sim_time
# if sime time gap is not enough, you need to add a cooldown time to it.
lastExcStart[task] += task_run_time + cooldown
sim_time = lastExcStart[task]
return sim_time + task_run_time
print(final_time([1, 1, 2, 1], 2))
print(final_time([1, 1, 2, 1, 2, 2], 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment