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 matesik1995
def minutes(duration) :
if duration%60 :
duration=duration//60+1
else :
duration=duration//60
return duration
def cost(duration):
cost = 0
if duration<=100 :
cost=duration
else :
cost=(duration-100)*2+100
return cost
def total_cost(calls):
temp = calls[0][:10]
daily = 0
ret = 0
for i in range(len(calls)) :
if calls[i][:10] == temp :
daily+=minutes(int(calls[i][20:]))
else :
ret+= cost(daily)
daily=0
daily+=minutes(int(calls[i][20:]))
temp = calls[i][:10]
ret+= cost(daily)
return ret
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"
Dec. 10, 2016