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 marcelina.gorzelana
import math
def total_cost(calls):
res = 0
i = 0
while i < len(calls):
daytotal = math.ceil( int( calls[i][ 20 : ]) / 60)
j = i
repeated = 0
while j < len(calls):
if calls[i][ : 10] == calls[j][ : 10] and i != j:
daytotal+= math.ceil( int( calls[j][ 20 : ]) / 60)
repeated+= 1
j+= 1
if daytotal <= 100:
res+= daytotal
else:
res+= 100 + ((daytotal - 100) * 2)
i+= 1 + repeated
return res
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. 7, 2016