Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. def get_seconds(time):
  2. hours = int(time[:2])
  3. minutes = int(time[3:5])
  4. seconds = int(time[6:])
  5. return 3600 * hours + 60 * minutes + seconds
  6.  
  7. def is_in_range(time, min_time, max_time):
  8. time_seconds = get_seconds(time)
  9. min_time_seconds = get_seconds(min_time)
  10. max_time_seconds = get_seconds(max_time)
  11. return min_time_seconds <= time_seconds <= max_time_seconds
  12.  
  13. def generate_times_for_hour(hour):
  14. if len(set(hour)) == 2:
  15. return set([hour + ':' + m1 + s1 + ':' + m2 + s2 for m1 in hour for s1 in hour for m2 in hour for s2 in hour])
  16. else:
  17. letter = hour[0]
  18. letters = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
  19. combinations = [letter + x for x in letters]
  20. result = set()
  21. for xs in combinations:
  22. result = result.union(set([hour + ':' + m1 + s1 + ':' + m2 + s2 for m1 in xs for s1 in xs for m2 in xs for s2 in xs]))
  23. return result
  24.  
  25. def solution(S, T):
  26. startHour = int(S[:2])
  27. endHour = int(T[:2])
  28. result = 0
  29. for h in range(startHour, endHour+1):
  30. result += len([time for time in generate_times_for_hour(str(h)) if is_in_range(time, S, T)])
  31. return result
  32.  
  33.  
  34. # print(solution("11:12:43", "16:13:10"))
  35. print(solution("22:22:21", "22:22:23"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement