Skip to content

Instantly share code, notes, and snippets.

@Furkan-Gulsen
Created January 11, 2024 22:13
Show Gist options
  • Save Furkan-Gulsen/f5aaedb16c536fcc4d205f8e1ed997be to your computer and use it in GitHub Desktop.
Save Furkan-Gulsen/f5aaedb16c536fcc4d205f8e1ed997be to your computer and use it in GitHub Desktop.
Get Task Index at Cycle
def get_task_index_at_cycle(jobs, cycle):
execution_order = sorted(range(len(jobs)), key=lambda k: (jobs[k], k))
total_time = sum(jobs)
cycle = cycle % total_time + 1 if cycle >= total_time else cycle
current_time = 0
for job_index in execution_order:
current_time += jobs[job_index]
if cycle <= current_time:
return job_index
return execution_order[-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment