Tip:
Highlight text to annotate it
X
You might remember for P = 0.5 then you go to the truth table, you’ll find the answer is 0.375.
If you set P to 0.8, the number actually goes down at 0.096.
So, you can check the implementation to see if you get the exact the same numbers.
So, here’s my result--when you build the truth table,
you’ll find that exact the 3 possible outcomes have had exactly once; it’s H T T, T H T, and T T H.
So, of the 8 possible outcomes of the coin flips, those 3 are the ones you want to count.
Now, each has exactly the same probability of P for heads x (1 - P) x (1 - P).
So, they get all 3 of them together, we just multiply these by 3.
And this is how it looks in the source code 3 x P x (1 - P) x (1 - P) if,
for example, I give this input 0.8, then I get 0.096 as an answer.
But if you never programmed before and you got this fight, then congratulations!
You might be actually a programmer.
Obviously, if you programmed before, this should relatively straightforward but it’s fun to practice.
Let’s now go to a case maybe of 2 coins.