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

Function total_frequency_distribution

project_euler/problem_205/sol1.py:17–38  ·  view source on GitHub ↗

Returns frequency distribution of total >>> total_frequency_distribution(sides_number=6, dice_number=1) [0, 1, 1, 1, 1, 1, 1] >>> total_frequency_distribution(sides_number=4, dice_number=2) [0, 0, 1, 2, 3, 4, 3, 2, 1]

(sides_number: int, dice_number: int)

Source from the content-addressed store, hash-verified

15
16
17def total_frequency_distribution(sides_number: int, dice_number: int) -> list[int]:
18 """
19 Returns frequency distribution of total
20
21 >>> total_frequency_distribution(sides_number=6, dice_number=1)
22 [0, 1, 1, 1, 1, 1, 1]
23
24 >>> total_frequency_distribution(sides_number=4, dice_number=2)
25 [0, 0, 1, 2, 3, 4, 3, 2, 1]
26 """
27
28 max_face_number = sides_number
29 max_total = max_face_number * dice_number
30 totals_frequencies = [0] * (max_total + 1)
31
32 min_face_number = 1
33 faces_numbers = range(min_face_number, max_face_number + 1)
34 for dice_numbers in product(faces_numbers, repeat=dice_number):
35 total = sum(dice_numbers)
36 totals_frequencies[total] += 1
37
38 return totals_frequencies
39
40
41def solution() -> float:

Callers 1

solutionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected