Last active
September 22, 2018 22:15
-
-
Save d5h/b52f87f2672813673b0c51529041cf1b to your computer and use it in GitHub Desktop.
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
def cost(duty): | |
""" | |
Assume units of pay is "hours". I.e. for each hour worked increment by 1. | |
Rules: | |
1. Drivers get paid for each hour they work, but not the break. | |
2. They get a minimum pay of eight hours for coming into work (known as guarantee pay). | |
3. They get 1.5x pay for each hour they work over eight hours(overtime pay). | |
4. Each duty over four hours should allow the driver to have a break. | |
""" | |
# Rule 1 & 2 | |
pay = max(len(duty), 8) | |
# Rule 3 | |
if len(duty) > 8: | |
pay += 0.5 * (len(duty) - 8) | |
# Rule 4: If there's no break, set pay to a very large value, since it violates a | |
# basic labor law. | |
if len(duty) > 4: | |
first_hour = duty[0][1] | |
last_hour = duty[-1][1] | |
if last_hour - first_hour + 1 == len(duty): | |
# No break | |
pay = 1e6 | |
return pay | |
def main(): | |
routes = 'ABCD' | |
start_hour = 9 | |
end_hour = start_hour + 12 | |
trips = generate_trips(routes, start_hour, end_hour) | |
duties = generate_duties(5, trips) | |
duties_with_costs = [(cost(duty), duty) for duty in duties] | |
pprint(duties_with_costs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment