Skip to content

Commit b79e0c1

Browse files
authored
Update probability_of_n_heads_in_m_tossing.py
1 parent b84ac59 commit b79e0c1

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

maths/probability_of_n_heads_in_m_tossing.py

+26-30
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,39 @@
1-
"""
2-
The probability of getting exactly n heads in m tossing.
31

4-
Algorithm Explanation:
5-
If you toss 0 time -> 0 head
6-
Distribution [1] -> Meaning: 1 in the 0-index
72

8-
If you toss 1 time -> 0 or 1 head
9-
Distribution [0.5 0.5] -> Meaning: 0.5 in both indexes
3+
import numpy as np
104

11-
If you toss 2 times -> 0 to 2 heads
12-
Distribution [0.25 0.5 0.25] ->
13-
Meaning: probability of n heads from the distribution
14-
{HH, HT, TH, TT}
155

16-
If you toss 3 times -> 0 to 3 heads
17-
Distribution [0.125 0.375 0.375 0.125] ->
18-
Meaning: probability of n heads from the distribution
19-
{HHH, HHT, HTH, HTT, THH, THT, TTH, TTT}
6+
def probability_of_n_heads_in_m_tossing(head_count: int, toss_count: int) -> int:
7+
"""
8+
The probability of getting exactly n heads in m tossing.
209
21-
Therefore,
22-
Probability_distribution(N+1) =
23-
[Probability_distribution(N) 0]/2 + [0 Probability_distribution(N)]/2
10+
Algorithm Explanation:
11+
If you toss 0 time -> 0 head
12+
Distribution [1] -> Meaning: 1 in the 0-index
2413
25-
I used that method in my paper
26-
Titled: Uncertainty-aware Decisions in Cloud Computing:
27-
Foundations and Future Directions
28-
Journal: ACM Computing Surveys (CSUR)
29-
"""
14+
If you toss 1 time -> 0 or 1 head
15+
Distribution [0.5 0.5] -> Meaning: 0.5 in both indexes
3016
31-
import numpy as np
17+
If you toss 2 times -> 0 to 2 heads
18+
Distribution [0.25 0.5 0.25] ->
19+
Meaning: probability of n heads from the distribution
20+
{HH, HT, TH, TT}
3221
22+
If you toss 3 times -> 0 to 3 heads
23+
Distribution [0.125 0.375 0.375 0.125] ->
24+
Meaning: probability of n heads from the distribution
25+
{HHH, HHT, HTH, HTT, THH, THT, TTH, TTT}
3326
34-
def probability_of_n_heads_in_m_tossing(head_count: int, toss_count: int) -> int:
35-
"""
36-
Calculate the factorial of specified number (n!).
27+
Therefore,
28+
Probability_distribution(N+1) =
29+
[Probability_distribution(N) 0]/2 + [0 Probability_distribution(N)]/2
30+
31+
I used that method in my paper
32+
Titled: Uncertainty-aware Decisions in Cloud Computing:
33+
Foundations and Future Directions
34+
Journal: ACM Computing Surveys (CSUR)
3735
38-
>>> import math
39-
>>> all(factorial(i) == math.factorial(i) for i in range(20))
40-
True
36+
>>> import numpy as np
4137
>>> Probability_of_n_heads_in_m_tossing(.2,.5)
4238
Traceback (most recent call last):
4339
...

0 commit comments

Comments
 (0)