Drill

ProblemsPython › events

How many openings in the coming weeks

mediumeventsPython

A recurring weekly pattern marks which of the seven weekdays are open. Count the total openings over a number of full weeks.

weekly_openings(pattern: list<bool>, weeks: int) → int

Solve it in the editor →

Where you start

def weekly_openings(pattern: list[bool], weeks: int) -> int:
    

Worked examples

CallResult
weekly_openings([True, False, True, False, True, False, False], 4)12
weekly_openings([False, False, False, False, False, False, False], 10)0
weekly_openings([True, True, True, True, True, True, True], 2)14
weekly_openings([True, False, False, False, False, False, False], 0)0

Hint

Count the true entries in the pattern once, then multiply.

Reference solution in Python
def weekly_openings(pattern: list[bool], weeks: int) -> int:
    per_week = 0
    for d in pattern:
        if d:
            per_week += 1
    return per_week * weeks

The same problem in another language

More events problems in Python