Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 366f1ff

Browse files
committedJun 12, 2024·
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent c987949 commit 366f1ff

File tree

1 file changed

+40
-41
lines changed

1 file changed

+40
-41
lines changed
 

‎maths/probability_of_n_heads_in_m_tossing.py

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,56 @@
1-
21
import numpy as np
32

43

54
def probability_of_n_heads_in_m_tossing(head_count: int, toss_count: int) -> int:
65
"""
7-
The probability of getting exactly n heads in m tossing.
6+
The probability of getting exactly n heads in m tossing.
87
9-
Algorithm Explanation:
10-
If you toss 0 time -> 0 head
11-
Distribution [1] -> Meaning: 1 in the 0-index
8+
Algorithm Explanation:
9+
If you toss 0 time -> 0 head
10+
Distribution [1] -> Meaning: 1 in the 0-index
1211
13-
If you toss 1 time -> 0 or 1 head
14-
Distribution [0.5 0.5] -> Meaning: 0.5 in both indexes
12+
If you toss 1 time -> 0 or 1 head
13+
Distribution [0.5 0.5] -> Meaning: 0.5 in both indexes
1514
16-
If you toss 2 times -> 0 to 2 heads
17-
Distribution [0.25 0.5 0.25] ->
18-
Meaning: probability of n heads from the distribution
19-
{HH, HT, TH, TT}
15+
If you toss 2 times -> 0 to 2 heads
16+
Distribution [0.25 0.5 0.25] ->
17+
Meaning: probability of n heads from the distribution
18+
{HH, HT, TH, TT}
2019
21-
If you toss 3 times -> 0 to 3 heads
22-
Distribution [0.125 0.375 0.375 0.125] ->
23-
Meaning: probability of n heads from the distribution
24-
{HHH, HHT, HTH, HTT, THH, THT, TTH, TTT}
20+
If you toss 3 times -> 0 to 3 heads
21+
Distribution [0.125 0.375 0.375 0.125] ->
22+
Meaning: probability of n heads from the distribution
23+
{HHH, HHT, HTH, HTT, THH, THT, TTH, TTT}
2524
26-
Therefore,
27-
Probability_distribution(N+1) =
28-
[Probability_distribution(N) 0]/2 + [0 Probability_distribution(N)]/2
25+
Therefore,
26+
Probability_distribution(N+1) =
27+
[Probability_distribution(N) 0]/2 + [0 Probability_distribution(N)]/2
2928
30-
I used that method in my paper
31-
Titled: Uncertainty-aware Decisions in Cloud Computing:
32-
Foundations and Future Directions
33-
Journal: ACM Computing Surveys (CSUR)
29+
I used that method in my paper
30+
Titled: Uncertainty-aware Decisions in Cloud Computing:
31+
Foundations and Future Directions
32+
Journal: ACM Computing Surveys (CSUR)
3433
35-
>>> import numpy as np
36-
>>> probability_of_n_heads_in_m_tossing(.2,.5)
37-
Traceback (most recent call last):
38-
...
39-
ValueError: The function only accepts integer values
40-
>>> probability_of_n_heads_in_m_tossing(-1,5)
41-
Traceback (most recent call last):
42-
...
43-
ValueError: The function is not defined for negative values
44-
>>> probability_of_n_heads_in_m_tossing(3,2)
45-
Traceback (most recent call last):
46-
...
47-
ValueError: Head count should be smaller than toss count
34+
>>> import numpy as np
35+
>>> probability_of_n_heads_in_m_tossing(.2,.5)
36+
Traceback (most recent call last):
37+
...
38+
ValueError: The function only accepts integer values
39+
>>> probability_of_n_heads_in_m_tossing(-1,5)
40+
Traceback (most recent call last):
41+
...
42+
ValueError: The function is not defined for negative values
43+
>>> probability_of_n_heads_in_m_tossing(3,2)
44+
Traceback (most recent call last):
45+
...
46+
ValueError: Head count should be smaller than toss count
4847
49-
>>> probability_of_n_heads_in_m_tossing(1,1)
50-
0.5
51-
>>> probability_of_n_heads_in_m_tossing(0,2)
52-
0.25
53-
>>> probability_of_n_heads_in_m_tossing(2,3)
54-
0.375
48+
>>> probability_of_n_heads_in_m_tossing(1,1)
49+
0.5
50+
>>> probability_of_n_heads_in_m_tossing(0,2)
51+
0.25
52+
>>> probability_of_n_heads_in_m_tossing(2,3)
53+
0.375
5554
"""
5655
if head_count != int(head_count) or toss_count != int(toss_count):
5756
raise ValueError("The function only accepts integer values")

0 commit comments

Comments
 (0)
Please sign in to comment.