Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Call to Home by Molot
from math import ceil
def total_cost(calls):
call_list = [(c.split()[0], ceil(int(c.split()[2])/60)) for c in calls]
days = {d: 0 for d in set(list(zip(*call_list))[0])}
for call in call_list: days[call[0]] += call[1]
for k,v in days.items(): days[k] = min(v,100) * 1 + max(0, v - 100) * 2
return sum(days.values())
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert total_cost(("2014-01-01 01:12:13 181",
"2014-01-02 20:11:10 600",
"2014-01-03 01:12:13 6009",
"2014-01-03 12:13:55 200")) == 124, "Base example"
assert total_cost(("2014-02-05 01:00:00 1",
"2014-02-05 02:00:00 1",
"2014-02-05 03:00:00 1",
"2014-02-05 04:00:00 1")) == 4, "Short calls but money..."
assert total_cost(("2014-02-05 01:00:00 60",
"2014-02-05 02:00:00 60",
"2014-02-05 03:00:00 60",
"2014-02-05 04:00:00 6000")) == 106, "Precise calls"
July 3, 2018
Comments: