This programming assignment requires you to implement two functions that are par
ID: 3921342 • Letter: T
Question
This programming assignment requires you to implement two functions that are part of a server auditing application. Time is specified as an integer. Typically we specify time 0 to be a specific starting time eg.. "Jan 1, 2016 at 12 midnight" and count the number of seconds elapsed since that time. A server log is a list of N time intervals, wherein each interval (phi_i, u_i) specifics that some user was logged into the company server starting at time phi_i and ending at time u_i, with the starting/ending time points included. [(phi_1, u_1), (phi_2, u_2), (phi_3, u_3),...(phi_N, u_N)] You can assume that phi_i,
Explanation / Answer
Here is the code :
#!/usr/bin/python
# Function definition is here
def free_time_interval( array, endTime ):
intervals = []
# Creating a list and making all values to be 0.
for index in range(0,endTime):
intervals.append([])
intervals.append(0);
#based on start time and end time , initializing the previosuly created list with 1
# so if an index contains 1 it means a user logged in at that time and if it is 0 then no one logged in
for row in range(0,len(array)):
startInt = array[row][0]
if(array[row][1] >= endTime):
endInt = endTime
else:
endInt = array[row][1]
while(startInt <= endInt):
intervals[startInt].append(1)
startInt = startInt+1
# Printing the values based on 1 and 0
count = 0
for rows in range(0,len(intervals)):
if(intervals[rows][0] == 0):
if(count%2 == 0):
print(rows , " ")
else:
print(rows, ", ",rows+1)
count = count+1
# Now you can call changeme function
array = []
array.append([])
array.append([])
array[0].append(1)
array[0].append(2)
array[1].append(3)
array[1].append(7)
free_time_interval( array, 5 )
Output would be:
0,1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.