Unit4Section2.py
unknown
python
a month ago
1.8 kB
3
Indexable
def find_task_pair(task_times, available_time): # 2 pointer # avaiable time - task time for i in range(len(task_times)): time = available_time - task_times[i] if time in task_times[i+1:]: return True return False task_times = [30, 45, 60, 90, 120] available_time = 105 # print(find_task_pair(task_times, available_time)) task_times_2 = [15, 25, 35, 45, 55] available_time = 100 # print(find_task_pair(task_times_2, available_time)) task_times_3 = [20, 30, 50, 70] available_time = 60 # print(find_task_pair(task_times_3, available_time)) # Problem 2 #[(900, 1100), (1300, 1500), (1600, 1800)] # 1300 - 1100 = 200/100 = 2 # 1600 - 1500 = 100/100 = 1 # 1300 - 1100 = 200/100 = 2 def conversion(time): hours = int(time/100) minutes = time % 100 return hours + (minutes/60) # 30 -> .5 def find_smallest_gap(work_sessions): smallest = float("inf") # Iterate through list for i in range(len(work_sessions) - 1): end = work_sessions[i][1] start = work_sessions[i+1][0] # Find curr work gap gap = ((conversion(start) - conversion(end))) smallest = min(smallest, gap) # hr = time//100 temp = (smallest/100) * 60 if temp < 1: return int(temp * 100) else: return int(temp * 60) #issues .30 -> turns to 0 when (int) is called ## 11:30 - 12:00 ## 11:45 - 12:15 ## 60 - (min in start) + (min in end) work_sessions = [(900, 1100), (1300, 1500), (1600, 1800)] print(find_smallest_gap(work_sessions)) work_sessions_2 = [(1000, 1130), (1200, 1300), (1400, 1500)] print(find_smallest_gap(work_sessions_2)) work_sessions_3 = [(900, 1100), (1115, 1300), (1315, 1500)] print(find_smallest_gap(work_sessions_3)) # Example Output: # 60 # 30 # 15
Editor is loading...
Leave a Comment