Skip to content

Instantly share code, notes, and snippets.

View martasd's full-sized avatar

Martin Dluhos martasd

  • profiq
  • Czech Republic
View GitHub Profile
@martasd
martasd / sum_intervals.py
Created November 22, 2023 14:26
Sum intervals
def sum_intervals(interval_list):
interval_list.sort(key=lambda lst: lst[0])
# sum numbers in the interval with the lowest begin number
begin, end = interval_list[0]
max = end
result = sum(range(begin, end + 1))
# sum numbers from the remaining intervals
for begin, end in interval_list[1:]: