Skip to content

Instantly share code, notes, and snippets.

@bkwaku

bkwaku/activity_5.py

Created Oct 13, 2016
Embed
What would you like to do?
my_list = [(7,9),(8,10),(13,17)]
def check_free_time(my_list):
free_time = []
my_list.sort()
if my_list[0][0] > 0: #if the first meeting is not at midnight
t = (0, my_list[0][0])
free_time.append(t)
#if last meeting is not at midnight
if my_list[-1][1] < 23:
f = (my_list[-1][1],0)
free_time.append(f)
i = 1
for tupl in my_list:
if i <= len(my_list) - 1:
if tupl[1] < my_list[i][0]:
free = (tupl[1],my_list[i][0])
free_time.append(free)
i+=1
return free_time
print check_free_time(my_list)
def merge_sort(list)
list.sort!
left,right = list.each_slice( (list.size/2.0).round ).to_a
i = 0
new_list = Array.new
right.reverse!
for item in left
new_list << item
new_list << right[i]
i = i +1
end
return new_list
end
puts merge_sort([1,5,4,7,6,3,2])
def subsets(my_list):
sub = [[]]
for i in my_list:
for j in sub:
sub = sub + [j + [i]]
return sub
print (subsets((1,2,3,4)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment