How many openings in the coming weeks
A recurring weekly pattern marks which of the seven weekdays are open. Count the total openings over a number of full weeks.
- The pattern list has exactly 7 booleans, one per weekday starting Monday.
- Each true entry is one opening per week.
- Multiply the weekly count by the number of weeks.
- Zero weeks gives zero openings.
weekly_openings(pattern: list<bool>, weeks: int) → int
Where you start
def weekly_openings(pattern: list[bool], weeks: int) -> int:
Worked examples
| Call | Result |
|---|---|
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