In addition to contributing to Stack Overflow and other SE sites, I like to ride public transit during my free time. I'd be spending a fortune on cash fare and/or bus tickets every month if I didn't have a bus pass. But for the average passenger, how much would you need to ride to make it worthwhile to buy a pass?
Input
Two parameters: Passenger age and transit usage report.
Standard loopholes apply. You can read input from CLI arguments, function arguments, or a file (whichever works best for your language).
Transit usage log format
Each line represents a trip:
<date> <time> <route number> <start> à <destination>
<date> <time> <route number> <start> à <destination> // comments, if any
Date is in ISO 8601 format. Time is 24 hour format (hours and minutes, both with leading zeros). The remaining information on the line is irrelevant for this question.
Fare structure
Tickets are $1.60 each.
Child (0-5) Child (6-12) Student (13-19) Adult (20+)
Cash Free 1.90 3.55 3.55
Tickets Free 1 2 2
DayPass Free 8.30 8.30 8.30
Monthly pass Free n/A 82.25 103.25
Transfers
When paying with cash or tickets, a transfer (proof of payment) will be provided. The validity of the transfer is calculated as follows:
- Until 04:30 the next day if time of boarding is after 22:00, else
- 105 minutes from time of boarding on weekends, else
- 90 minutes from time of boarding
If you have a valid transfer at the start of a trip, you do not have to pay anything.
For the purposes of this question, make the following assumptions:
- All routes cost the same
- You never lose your transfer or day pass
- You do not have a transfer from the last day of the previous month.
Day pass
If more than $8.30 in cash is spent in a day, a day pass is cheaper.
A day pass is valid from 03:00 to 03:00 the next day. If a day pass is purchased at 02:30, it is only good for 30 minutes!
Output
Output may be in the form of a return value or written to STDOUT. A trailing newline is permitted.
Your program/function must output the cost of each option as follows (order does not matter):
C: $50.45
T: $44.1
J: $47.25
P: $100.75
J represents the calculation for a combination of cash with day passes where a day pass would have been cheaper.
Numbers must be truncated to at most two decimal places. Trailing zeros can be omitted.
For passengers age 6 through 12, passes are unavailable so any non-digit output for P
is OK (whether it be false, empty string, nil, null, not a number, "Infinity", etc.)
Bonus
-5% if you indicate the least expensive valid option in the output by printing any printable character before method of payment. For example:
P: $NaN
C: $117.80
*T: $99.20
J: $117.80
Test cases
Input transit usage log
body {white-space: pre; font-family: monospace}
2015-04-01 02:28 95 Barrhaven Centre à Laurier
2015-04-01 06:31 98 Laurier à Tunney's Pasture
2015-04-01 06:51 176X Tunney's Pasture à Merivale/Rossdale
2015-04-01 08:06 176 Merivale/Family Brown à Laurier
2015-04-01 22:16 97 Campus à Lincoln Fields
2015-04-01 22:51 95 Lincoln Fields à Barrhaven Centre
2015-04-02 02:00 95 Barrhaven Centre à Laurier
2015-04-02 19:01 95 Campus à Barrhaven Centre
2015-04-02 22:31 170 Barrhaven Centre à Fallowfield
2015-04-02 23:22 95 Fallowfield à Trim
2015-04-02 00:41 95 Trim à Barrhaven Centre
2015-04-02 03:48 95 Barrhaven Centre à Laurier
2015-04-02 20:25 95X Laurier à Mackenzie King
2015-04-02 20:49 95 Mackenzie King à Barrhaven Centre
2015-04-02 23:58 95 Barrhaven Centre à Laurier
2015-04-04 21:26 96 Laurier à Lincoln Fields
2015-04-04 21:51 94 Lincoln Fields à Fallowfield
2015-04-04 22:10 95 Fallowfield à Barrhaven Centre
2015-04-04 22:38 95 Barrhaven Centre à Hurdman
2015-04-04 23:24 95 Hurdman à Mackenzie King
2015-04-05 00:03 1 Dalhousie/York à Johnston/Bank
2015-04-05 00:43 97 Greenboro à Lincoln Fields
2015-04-06 01:41 95 Lincoln Fields à Fallowfield
2015-04-06 02:11 95 Fallowfield à Barrhaven Centre
2015-04-06 05:21 95 Longfields à Laurier
2015-04-06 18:17 94 Laurier à Mackenzie King
2015-04-06 18:49 95 Mackenzie King à Barrhaven Centre
2015-04-06 23:18 95 Barrhaven Centre à Place d'Orléans
2015-04-06 00:41 95 Place d'Orléans à Barrhaven Centre
2015-04-06 02:01 95 Barrhaven Centre à Laurier
2015-04-06 19:15 94 Laurier à Mackenzie King
2015-04-06 19:49 95 Mackenzie King à Barrhaven Centre
2015-04-06 23:51 170 Strandherd à Fallowfield
2015-04-07 00:21 DH Fallowfield à Baseline
2015-04-07 00:39 95 Baseline à Laurier
2015-04-07 17:20 71 Mackenzie King à Berrigan/Edge
2015-04-07 23:18 95 Barrhaven Centre à Laurier
2015-04-09 00:40 95 Trim à Barrhaven Centre
2015-04-09 02:00 95 Barrhaven Centre à Laurier
2015-04-09 16:32 41 Campus à Hurdman
2015-04-09 16:37 94 Hurdman à St. Laurent
2015-04-09 17:41 95 St. Laurent à Campus
2015-04-10 01:06 95 Laurier à Barrhaven Centre
2015-04-10 02:01 95 Barrhaven Centre à Laurier
2015-04-10 17:15 66 Campus à Lincoln Fields
2015-04-10 17:44 95 Lincoln Fields à Barrhaven Centre
2015-04-10 23:38 95 Barrhaven Centre à Longfields
2015-04-11 00:05 95 Longfields à Laurier
2015-04-11 01:30 95 Laurier à Barrhaven Centre
2015-04-11 04:47 95 Barrhaven Centre à Fallowfield //stop engine
2015-04-11 05:17 95 Fallowfield à Laurier
2015-04-11 17:15 94 Laurier à Mackenzie King
2015-04-11 17:41 95 Mackenzie King à Barrhaven Centre
2015-04-11 23:30 170 Barrhaven Centre à Fallowfield
2015-04-12 00:21 95 Fallowfield à Laurier
2015-04-12 17:30 98 Laurier à Mackenzie King
2015-04-12 21:25 95 Laurier à Barrhaven Centre
2015-04-12 23:18 95 Barrhaven Centre à Laurier
2015-04-13 07:01 16 Laurier/Cumberland à Tunney's Pasture
2015-04-13 07:27 176X Tunney's Pasture à Merivale/Meadowlands
2015-04-13 09:12 176 Merivale/Baseline à LeBreton
2015-04-13 09:21 96 LeBreton à Blair
2015-04-14 00:34 95 Laurier à Barrhaven Centre
2015-04-14 02:30 95 Barrhaven Centre à Laurier
2015-04-14 07:06 86C Laurier à Tunney's Pasture
2015-04-14 07:21 176 Tunney's Pasture à Merivale/Meadowlands
2015-04-14 08:54 86 Meadowlands/Merivale à Laurier
2015-04-14 18:43 97X Laurier à Hurdman
2015-04-14 18:55 95 Hurdman à St. Laurent
2015-04-14 19:23 95 St. Laurent à Barrhaven Centre
2015-04-14 23:18 95 Barrhaven Centre à Trim
2015-04-15 00:38 95 Trim à Laurier
2015-04-15 08:00 35 Laurier à Mackenzie King
2015-04-15 08:35 94 Mackenzie King à Campus
2015-04-15 22:15 95 Laurier à Barrhaven Centre
2015-04-16 02:01 95 Barrhaven Centre à Laurier
2015-04-16 21:01 95 Laurier à Woodroffe/Tallwood
2015-04-16 21:34 86 Meadowlands/Woodroffe à Meadowlands/Merivale
2015-04-16 21:56 176 Merivale/Meadowlands à Barrhaven Centre
2015-04-17 02:00 95 Barrhaven Centre à Laurier
2015-04-17 11:52 96 Laurier à Bayshore
2015-04-17 13:21 96 Bayshore à Campus
2015-04-17 22:10 95X Campus à Baseline
2015-04-17 22:47 95 Baseline à Barrhaven Centre
2015-04-18 02:53 95 Barrhaven Centre à Laurier
2015-04-18 20:14 86X Laurier à Hurdman
2015-04-18 20:22 94 Hurdman à St. Laurent
2015-04-18 20:44 94 St. Laurent à Fallowfield
2015-04-18 21:43 95 Fallowfield à Barrhaven Centre
2015-04-19 00:58 95 Barrhaven Centre à Laurier
2015-04-19 15:16 95 Laurier à Mackenzie King
2015-04-19 16:22 94 Mackenzie King à Hurdman
2015-04-19 16:34 98 Hurdman à South Keys
2015-04-19 16:51 97 South Keys à Airport
2015-04-19 17:21 97 Airport à Laurier
2015-04-19 21:30 95 Laurier à Barrhaven Centre
2015-04-19 23:18 95 Barrhaven Centre à Laurier
2015-04-20 19:30 95 Laurier à Barrhaven Centre
2015-04-20 23:18 95 Barrhaven Centre à Trim
2015-04-21 00:38 95 Trim à Laurier
2015-04-21 19:30 95 Laurier à Barrhaven Centre
2015-04-22 02:00 95 Barrhaven Centre à Laurier
2015-04-22 19:30 95 Laurier à Barrhaven Centre
2015-04-23 01:28 95 Barrhaven Centre à Woodroffe/Medhurst
2015-04-23 02:11 95 Woodroffe/Medhurst à Laurier
2015-04-23 19:30 95 Laurier à Barrhaven Centre
2015-04-23 23:18 95 Barrhaven Centre à Trim
2015-04-24 00:38 95 Trim à Laurier
2015-04-24 23:15 95 Laurier à Barrhaven Centre
2015-04-25 00:23 95 Barrhaven Centre à Rideau St.
2015-04-25 01:44 96 Rideau St à Laurier
2015-04-25 16:58 86B Laurier à Albert/Bank
2015-04-25 17:44 87 Mackenzie King à Laurier
2015-04-26 01:25 95 Laurier à Barrhaven Centre
2015-04-27 01:04 95 Laurier à Rideau St
2015-04-27 01:31 95 Rideau St à Laurier
2015-04-27 17:25 41 Campus à Heron/Baycrest
2015-04-27 17:54 112 Baycrest/Heron à Elmvale
2015-04-27 18:30 114 Elmvale à Hurdman
2015-04-27 18:41 94 Hurdman à Laurier
2015-04-29 02:02 95 Barrhaven Centre à Laurier
2015-04-29 17:01 8 Campus à Heron
2015-04-29 17:37 118 Heron à Baseline
2015-04-29 18:01 95 Baseline à Barrhaven Centre
2015-04-29 20:32 95 Barrhaven Centre à Mackenzie King
2015-04-29 21:31 2 Rideau St à Bank/Queen
2015-04-29 21:35 95 Albert/Bank à Barrhaven Centre
2015-04-30 02:02 95 Barrhaven Centre à Laurier
2015-04-30 02:20 86C Campus à Mackenzie King
2015-04-30 02:44 96 Mackenzie King à Campus
2015-04-30 19:36 95 Laurier à Strandherd
Output
$ node --harmony golfed.js trips.txt 5 "Toddler"
P: $0.00
C: $0.00
T: $0.00
J: $0.00
$ node --harmony golfed.js trips.txt 10 "Child"
P: $NaN
C: $117.80
T: $99.20
J: $117.80
$ node --harmony golfed.js trips.txt 15 "Student"
P: $82.25
C: $220.10
T: $198.40
J: $194.20
$ node --harmony golfed.js trips.txt 61 "Adult"
P: $103.25
C: $220.10
T: $198.40
J: $194.20