I am trying to calculate all possible combinations of given number of coin flips, using 10 as my test case for now. I believe that's Cartesian product but the last math class I had was ages ago. However, the twist is I want to calculate the most probable distributions first. This is the code I am starting with:
import itertools
for x in itertools.product(['H','T'],repeat=10):
print(x)
This will give me all possible combinations of 10 coin flips. But the first result is all heads, which is not very likely. My thinking is to start of with an even distribution, all combinations of 5 heads and 5 tails, and then continue with 4 heads and 6 tails (plus the inverse), 3 heads and 7 tails (plus the inverse), etc. However, I'm not quite sure if I can do this with itertools or some other built-in module or combination of modules.
If I use this:
import itertools
for x in itertools.permutations(['H','H','H','H','H','T','T','T','T','T']):
print(x)
then there are a lot of repeats, because it considers each 'H' and 'T' as unique. Any suggestions on how to tackle this?