Skip to content

Instantly share code, notes, and snippets.

@segaz2002
Last active February 27, 2020 23:25
Show Gist options
  • Save segaz2002/c7f2aa75b6dac2b9ef73662c8016e519 to your computer and use it in GitHub Desktop.
Save segaz2002/c7f2aa75b6dac2b9ef73662c8016e519 to your computer and use it in GitHub Desktop.
Sleeping Test
SCHEDULE_STRING = "Mon 01:00 - 23:00\nTue 01:00 - 23:00\nWed 01:00 - 23:00\nThu 01:00 - 23:00\nFri 01:00 - 23:00\nSat 01:00 - 23:00\nSun 01:00 - 21:00\n"
ONE_HOUR_IN_MINUTES = 60
def solution(s):
longest_time = 0
schedule_parts = [schedule for schedule in s.split("\n") if schedule != '']
for schedule in schedule_parts:
(day, allowance) = get_finish_time(schedule)
if allowance > longest_time:
longest_time = allowance
return (day, to_minutes(longest_time))
def get_finish_time(schedule):
end_of_day = 24.00
[day_and_start, finish] = schedule.split('-')
day = day_and_start.split(' ')[0]
float_finish_time = float(finish.strip().replace(':', '.'))
time_diff = end_of_day - float_finish_time
a = (day, time_diff)
return a
def to_minutes(hour):
return hour * ONE_HOUR_IN_MINUTES
print(solution(SCHEDULE_STRING))
#TODO
# take care of the other case of 55x minutes in case of fractions of hours
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment