Skip to content

Instantly share code, notes, and snippets.

@itzbernoulli
Last active October 13, 2016 22:30
Show Gist options
  • Save itzbernoulli/41e484d92829611a37f566e0ebe2446e to your computer and use it in GitHub Desktop.
Save itzbernoulli/41e484d92829611a37f566e0ebe2446e to your computer and use it in GitHub Desktop.
#This code sorts through an array of tuples containing the start and end times of meetings
#then prints out all the available free time during the day in which a new meeting can be scheduled
#This code is written in Python
def free_hours(meeting_time):
start_time = 0
end_time = 0
start = False
end = False
free= []
hours =[0 for i in range(0,24)]
for i in meeting_time:
time = range(i[0],i[-1]+1)
for x in time:
hours[x] = 1
for i in range(0,len(hours)):
#print i
if hours[i] == 0 and start == False:
start = True
end = False
start_time = i-1
free.append(start_time)
elif hours[i] == 1 and end == False:
end = True
start = False
end_time = i
free.append(end_time)
return free
meeting_time = [(7,9),(15,17),(20,22)]
print free_hours(meeting_time)
#This algorithm solves Linear and Simultaneous equations with 2 unknowns
#This code is written in Ruby
def check_arguments(v,arr)
if v>2
return "Number of Variables too large"
elsif v == 1 and arr.length!= 3
return "Inconsistent argument values"
elsif v == 2 and arr.length != 2
return "Inconsistent argument values"
end
if v == 1
return linear_equation(arr)
elsif v == 2
return simultaneous_equation(arr)
end
end
def linear_equation(arr)
result = (arr[2] - arr[1])/(arr[0] + 0.0)
return result
end
def simultaneous_equation(arr)
a= arr[0][0]
b= arr[0][1]
c= arr[1][0]
d= arr[1][1]
r1= arr[0][2]
r2= arr[1][2]
inv = 1.0/((a*d)-(b*c))
x = ((r1*d) + (-r2 * b)) * inv
y = ((-r1*c) + (r2 * a)) * inv
return x,y
end
var = 1
array = [2,4,6]
#array = [[2,4,5],[4,6,8]]
puts check_arguments(var,array)
This was possible through working with
Teressa Waithira
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment