Created
January 2, 2020 19:55
-
-
Save amcgregor/6839a068bb908565339853618c1372da to your computer and use it in GitHub Desktop.
A demonstration I use of an alternate use for a sorting algorithm.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bisect import bisect_left | |
periods = [ | |
# Time, is_open | |
('00:00', False), | |
('08:30', True), | |
('12:00', False), | |
('13:15', True), | |
('17:30', False), | |
('24:00', False), # For completeness sake. | |
] | |
def is_open(time): | |
applicable_period = bisect_left(periods, (time, None)) - 1 | |
return periods[applicable_period][1] | |
print(is_open('14:22')) # True # Pulled from the '13:15' "record". | |
print(is_open('06:44')) # False # Pulled from the '00:00' "record". |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment