There’s a game that works like this. You choose a random card from 13, ranked 2-A, bet on whether the next card will be higher or lower. If you’re right, the first card is returned to the deck, which is then fully shuffled and you have to guess whether the next card is higher or lower than the second card. Repeat this process until you’ve got 1 wrong or 5 right. What are the odds you win, assuming you play the odds, (always high 2-7, always low 9-A)?

I think that’s the sort of problem where you just have to run every possible option.

The deck has only 13 cards so there is no worry about ties.

On the *first* round your chance of success is 10/13 ~= 0.769231. If this were your chance *every* round, your chance of winning the first five rounds would be (10/13)^5 ~= 0.269329.

But subsequent rounds have lower odds. You want the control card to be a very high card or a very low card. For the initial round, an Ace or a Deuce is as likely as a Seven or Eight, but on subsequent *winning* rounds, Seven is about twice as likely as Ace. (Seven always wins, while Ace loses half the time. Turning up a medium card makes it *more* likely you win this round, but *less* likely you win the next round when that medium card becomes the control card.)

I don’t know any shortcut to get an exact expression so I followed **naita**’s suggestion and counted every single possibility. You get five wins with no losses with probability 740923/3234816 ~= 0.229046

That’s what I got too, once I went through my script to see why I didn’t get the same result. Turns out I only went to 4 wins.

I’ll show you my script if you show me yours.

Python 3

```
def hilo(n, k):
vec = [1.0] * n
while k:
vec = [max(sum(vec[i+1:])/(n-1), sum(vec[:i])/(n-1)) for i, x in enumerate(vec)]
k -= 1
return sum(vec)/n
print(hilo(13, 5))
```

It’s a function that gives the win probability for a deck of n cards where we need k successes to win.

It should be cut and pastable into this online Python 3 interpreter if you wish to play around with it.

I just realized my loop control was unnecessarily complicated. I cleaned it up a bit so it would be less distracting.

```
def hilo(n, k):
vec = [1.0] * n
while k:
vec = [max(sum(vec[i+1:])/(n-1), sum(vec[:i])/(n-1)) for i in range(n)]
k -= 1
return sum(vec)/n
print(hilo(13, 5))
```