MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_109/sol1.py:59–85  ·  view source on GitHub ↗

Count the number of distinct ways a player can checkout with a score less than limit. >>> solution(171) 42336 >>> solution(50) 12577

(limit: int = 100)

Source from the content-addressed store, hash-verified

57
58
59def solution(limit: int = 100) -> int:
60 """
61 Count the number of distinct ways a player can checkout with a score
62 less than limit.
63 >>> solution(171)
64 42336
65 >>> solution(50)
66 12577
67 """
68 singles: list[int] = [*list(range(1, 21)), 25]
69 doubles: list[int] = [2 * x for x in range(1, 21)] + [50]
70 triples: list[int] = [3 * x for x in range(1, 21)]
71 all_values: list[int] = singles + doubles + triples + [0]
72
73 num_checkouts: int = 0
74 double: int
75 throw1: int
76 throw2: int
77 checkout_total: int
78
79 for double in doubles:
80 for throw1, throw2 in combinations_with_replacement(all_values, 2):
81 checkout_total = double + throw1 + throw2
82 if checkout_total < limit:
83 num_checkouts += 1
84
85 return num_checkouts
86
87
88if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected