Skip to content

Instantly share code, notes, and snippets.

@kharioki
Created October 13, 2016 08:36
Show Gist options
  • Save kharioki/b5a42dab8709bac54e1954fa9cf2d695 to your computer and use it in GitHub Desktop.
Save kharioki/b5a42dab8709bac54e1954fa9cf2d695 to your computer and use it in GitHub Desktop.
def time_sort(time):
i = 0
music = time[i][1]
for music in range(len(time)-1,0,-1):
for i in range(music):
if time[i][1]>time[i+1][1]:
clock = time[i]
time[i] = time[i+1]
time[i+1] = clock
return time
def freetime(time):
sorted_list = time_sort(time)
print (sorted_list)
free = []
if sorted_list[0][0]>0:
free.append((0,sorted_list[0][0]))
for i in range(len(sorted_list)-1):
if sorted_list[i][1] < sorted_list[i+1][0]:
free.append((sorted_list[i][1], sorted_list[i+1][0]))
if sorted_list[0][0]>0:
free.append((sorted_list[-1][1],0))
return free
time = [(18,20), (7,8), (8,10), (13,17)]
print(freetime(time))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment