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 jcg
def total_cost(calls, threshold=100, cost_1=1, cost_2=2):
dict_day = {}
for x in calls :
date, hour, duration = x.split()
duration = (int(duration) - 1) // 60 + 1
dict_day[date] = dict_day.get(date, 0) + duration
return sum(cost_1 * dict_day[x] + (cost_2-cost_1) * max(dict_day[x]-threshold, 0) for x in dict_day)
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"
May 29, 2014
Comments: