# Risky Phone Plan

You have a phone plan that lets you talk 180 minutes a day. Every day that you go over your daily limit you have to pay a fine of F = Men, where M is the number of minutes you went over and n is the number of days you have gone over (e.g if I went 20 minutes over the daily limit and it's my 2nd day going over, I have to pay 20*e2 = 147.78).

You will be given a list of 12-hour clock times. Even-indexed times represent the start of a phone call, odd-indexed times represent the end of a phone call. Using this list find out how much money the person has to pay in fines.

# Notes

• Please use an approximation of e that is at least as accurate as 2.718
• You never need to round your answers or include a currency symbol.
• The first time in the list will always be an A.M (morning) time.
• Remember that in 12-hour time 1 comes after 12 (you can think of 12 as 0).
• A day starts at 12:00 AM and ends at 11:59 PM
• If a number is lower than the previous time, then that means that it is in the opposite (A.M./P.M) time range.
• A call will never start in one day and end in another.

# Test Cases

10:30
2:30
5:30
6:30


This person made two phone calls in one day. One from 10:30 A.M. to 2:30 P.M., another from 5:30 P.M to 6:30 P.M. In total, they talked for 5 hours this day, going 120 minutes over the daily limit. Since it's their first offense, they have to pay 120*e = $326.19 (yes, their phone plan is quite Draconic). 10:30 11:45 5:15 6:45 8:20 9:20 5:30 7:50 2:30 3:30  This person made several phone calls over 2 days. The first day they were on the phone from 10:30-11:45 A.M, 5:15-6:45 P.M., and 8:20-9:20 PM using a total of 225 minutes. That is an overage of 45 minutes. So their fine for the day is 45*e =$122.32.

The next day they talked from 5:30-7:50 A.M and 2:30-3:30 P.M., a total of 200 minutes. They went over by 20 minutes, and since it's their second offense they pay 20*e2 = $147.78 You output their total fee as$122.32 + $147.78 = $270.10

10:30
11:30
6:30
7:30
9:45
11:00
10:25
11:25
8:45
9:45
6:00
8:00
2:30
4:30

• Day 1:
• 10:30-11:30 A.M., 6:30-7:30 P.M., 9:45-11:00 P.M. = 195 minutes
• Fee: 15*e = $40.77 • Day 2: • 10:25-11:25 A.M., 8:45-9:45 P.M. = 120 minutes • Fee:$0
• Day 3:
• 6:00 - 8:00 A.M., 2:30-4:30 P.M. = 240 minutes
• Fee: 60*e2 = $443.34 Output:$40.77 + $0 +$443.34 = $484.11 • This sounds a lot like VerizonMath Jan 16, 2016 at 22:07 • @user8 Yes, as you can see in the first test case. Jan 17, 2016 at 1:45 • Would the call log 8:00 9:00 7:00 6:00 be parsed as Day 1 8:00AM - 9:00PM, Day 2 7:00AM - 6:00PM or be invalid? If it's valid it would break the rule that "If a number is lower than the previous time, then that means that it is in the opposite (A.M./P.M) time range". Jan 17, 2016 at 1:55 • @user8 no, the first part is parsed as 8-9 AM, the 2nd part is invalid bcuz it crosses from day 1 to day 2. Jan 17, 2016 at 2:00 • Oh sorry, I meant to write Day 1 8:00AM - 9:00AM. But thanks for clarifying. Jan 17, 2016 at 2:03 ## 1 Answer # Perl 5, 185 bytes @c=map{s/(.+):(.+)/$1%12*60+$2/er}<>;while(@c){$s=shift@c;$e=shift@c;$p+=0>($k=$e-$s)?720+$k:$k;if($e>$c[0]||$k<0){if($m||!@c){$f+=0>($p-=180)?0:$p*exp++$d;$p=0}$m=!$m}}printf'$%.2f',$f


Try it online!