Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
meh solution in Clear category for Call to Home by Leonix
from typing import Iterable, List
import math
def total_cost(calls: List[str]) -> int:
return sum(cost(duration) for duration in durations_by_day(calls))
def cost(duration: int) -> int:
""" Given total call duration per day, return total cost of that day. """
if duration <= 100:
return duration
return 100 + 2*(duration - 100)
def durations_by_day(calls: Iterable[str]) -> Iterable[int]:
""" Total call duration in minutes for each separate day. """
current_day = None
for c in calls:
day, _, duration = c.split(' ')
if day != current_day:
if current_day is not None:
yield current_duration
current_day = day
current_duration = 0
current_duration += int(math.ceil(int(duration) / 60.0))
if current_day is not None:
yield current_duration
June 4, 2019
Comments: