# Coin flip duel

Not to be flippant, but the duelist with priority pockets the change here.

This week's Riddler Express poses the following question: if you and your friend take turns flipping one coin until someone tallies 10 heads (who wins), what advantage does the first flipper have over their friend?

This can definitely be solved analytically, but I submitted a brute force solution coded in Julia. My paste got a shoutout the following week! ðŸŽ‰ (ãƒŽ^o^)ãƒŽðŸŽ‰

First, just using rand(Bool) for a coin flip, simulate one player's needed flips to get N heads, in one duel:

Then, all we need is to compare the result of this to the same call for another player. The edge for the first player comes down to the fact that they win with the condition <=, and conversely the second player only wins with >.

So, we can just run p1winpct for a large number of trials, and we should arrive at an approximation of player one's advantage.

For the target of 10 heads, out of 100 million trials, player one wins 53.3% of the time. Note that this is a 6.6 percentage point advantage over their trailing duelist.