diff --git a/src/tiaz0128/ch_08/solution_021.py b/src/tiaz0128/ch_08/solution_021.py index bf9ee1c..35897c5 100644 --- a/src/tiaz0128/ch_08/solution_021.py +++ b/src/tiaz0128/ch_08/solution_021.py @@ -1,2 +1,21 @@ +from collections import Counter + + def solution(want, number, discount): - return + answer = 0 + + wanted_items = {want[idx]: cnt for idx, cnt in enumerate(number)} + + for idx, item in enumerate(discount): + items = discount[idx : idx + 10] + counter = Counter(items) + + if all( + [ + cnt <= counter.get(category, False) + for category, cnt in wanted_items.items() + ] + ): + answer += 1 + + return answer