Bike Rentals, Part 1
The puzzle
A bike shop by the river keeps a paper log of every rental: the bike, when it went out and when it came back.
B04 09:05-10:30
B11 09:20-09:50
B02 09:40-12:15
Times are on a 24-hour clock. A bike is out from the minute it leaves up to, but not including, the minute it comes back: a bike returned at 10:30 can go out again at 10:30, and at that minute it counts once, not twice. The same bike can appear in several rentals.
The owner wants to know whether she has enough bikes. What is the most bikes out at the same moment during the day?
This lesson's input has the log, a blank line, and a list of times the owner will ask about in part 2. Part 1 only needs the log.
Task
- Complete
clock(s string) (int, error): turn"09:05"into minutes after midnight (545). Hours go from00to23and minutes from00to59; anything else is an error. - Complete
parseRental(line string) (Rental, error): read a line such asB04 09:05-10:30. A line without a bike, without both times, or that ends at or before its start is an error. - Complete
peak(rentals []Rental) int: the most bikes out at once.
Checking every minute of the day works for one day, but think about what happens with a year of logs. There's a way that only looks at the moments when something changes.