forked from KenMercusLai/checkio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Call to Home.py
32 lines (28 loc) · 1.24 KB
/
Call to Home.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from math import ceil
def total_cost(calls):
day_cost = {}
for i in calls:
# calc how many minutes for each day
day, _, seconds = i.split()
seconds = int(seconds)
minutes = ceil(seconds * 1.0 / 60)
if day in day_cost:
day_cost[day] += minutes
else:
day_cost[day] = minutes
return sum([day_cost[i] if day_cost[i] <= 100 else 100 + (day_cost[i] - 100) * 2 for i in day_cost])
if __name__ == '__main__':
# These "asserts" using only for self-checking and not necessary for
# auto-testing
assert total_cost((u"2014-01-01 01:12:13 181",
u"2014-01-02 20:11:10 600",
u"2014-01-03 01:12:13 6009",
u"2014-01-03 12:13:55 200")) == 124, "Base example"
assert total_cost((u"2014-02-05 01:00:00 1",
u"2014-02-05 02:00:00 1",
u"2014-02-05 03:00:00 1",
u"2014-02-05 04:00:00 1")) == 4, "Short calls but money..."
assert total_cost((u"2014-02-05 01:00:00 60",
u"2014-02-05 02:00:00 60",
u"2014-02-05 03:00:00 60",
u"2014-02-05 04:00:00 6000")) == 106, "Precise calls"