Skip to content

Commit 707b446

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent b62a774 commit 707b446

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

maths/probability_of_n_heads_in_m_tossing.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
"""
32
Algorithm Explanation:
43
If you toss 0 time -> 0 head
@@ -8,28 +7,28 @@
87
Distribution [0.5 0.5] -> Meaning: 0.5 in both indexes
98
109
If you toss 2 times -> 0 to 2 heads
11-
Distribution [0.25 0.5 0.25] ->
12-
Meaning: probability of n heads from the distribution
10+
Distribution [0.25 0.5 0.25] ->
11+
Meaning: probability of n heads from the distribution
1312
{HH, HT, TH, TT}
1413
1514
If you toss 3 times -> 0 to 3 heads
16-
Distribution [0.125 0.375 0.375 0.125] ->
17-
Meaning: probability of n heads from the distribution
15+
Distribution [0.125 0.375 0.375 0.125] ->
16+
Meaning: probability of n heads from the distribution
1817
{HHH, HHT, HTH, HTT, THH, THT, TTH, TTT}
1918
2019
Therefore,
21-
Probability_distribution(N+1) =
20+
Probability_distribution(N+1) =
2221
[Probability_distribution(N) 0]/2 + [0 Probability_distribution(N)]/2
2322
2423
I used that method in my paper
25-
Titled: Uncertainty-aware Decisions in Cloud Computing:
24+
Titled: Uncertainty-aware Decisions in Cloud Computing:
2625
Foundations and Future Directions
2726
Journal: ACM Computing Surveys (CSUR)
2827
"""
2928

30-
3129
import numpy
3230

31+
3332
def probability_of_n_heads_in_m_tossing(head_count: int, toss_count: int) -> int:
3433
"""
3534
Calculate the factorial of specified number (n!).
@@ -68,6 +67,6 @@ def probability_of_n_heads_in_m_tossing(head_count: int, toss_count: int) -> int
6867

6968
for iter1 in range(toss_count):
7069
value = numpy.append(value, [0], axis=0) + numpy.append([0], value, axis=0)
71-
value = value/2
70+
value = value / 2
7271

7372
return value[head_count]

0 commit comments

Comments
 (0)