Teaser 3202: Long odds
From The Sunday Times, 4th February 2024 [link] [link]
A group of fewer than twenty of us play a simple gambling game. We have a set of cards labelled 1, 2, 3, … up to a certain number and each player is allocated one of the cards at random. There is a prize for the player with the highest number from those allocated, and a booby prize for the lowest.
In a recent game I was unfortunately allocated a very middling number (in fact exactly half of the highest possible number). I calculated that my chance of winning the booby prize was 1 in N (where N is a whole number) and that my chance of winning the top prize was even lower at 1 in 2N.
How many cards are there in the set, and how many players?
[teaser3202]
Jim Randell 5:05 pm on 2 February 2024 Permalink |
This Python program runs in 71ms. (Internal runtime is 3.3ms).
from enigma import (Rational, irange, multiply, printf) Q = Rational() # consider number of players for k in irange(2, 19): # consider number of cards (must be even) for n in irange(k + (k % 2), 100, step=2): # my card is x (= n/2) x = n // 2 if x < k: continue # chance of winning the booby prize = pB # consider each of the (k - 1) other players # each of them must have one of the x cards higher than mine pB = multiply(Q(x + 1 - i, n - i) for i in irange(1, k - 1)) if pB.numerator != 1: continue # chance of winning the top prize = pT # consider each of the (k - 1) other players # each of them must have one of the (x - 1) cards lower than mine pT = multiply(Q(x - i, n - i) for i in irange(1, k - 1)) if not (2 * pT == pB): continue # output solution printf("{k} players, {n} cards -> x={x} pB={pB} pT={pT}")Solution: There were 40 cards in the set. And there were 11 players in the game.
The cards are numbered 1 … 40, so the setter was dealt the 20 card.
The probability of each of the remaining 10 players receiving a card that is higher than 20 is:
And the probability of each of the remaining 10 players receiving a card that is lower than 20 is:
Analytically:
If my card is x, then there are 2x cards (numbered 1 … 2x).
And if there are (k + 1) players in total (i.e. k other players), then:
The denominators are the same so:
And we can simplify:
so we can consider possible values for k (= 1 .. 18) and look for situations where pB = 1/N.
The internal runtime of this program is 200µs.
from enigma import (irange, factorial, fraction, printf) # consider number of players - 1 for k in irange(1, 18): # probability of winning booby prize (pBn, pBd) = fraction(factorial(2 * k, k), factorial(4 * k - 1, 3 * k - 1)) if pBn != 1: continue # output solution (n, k, pTd) = (4 * k, k + 1, 2 * pBd) printf("{k} players, {n} cards -> pB=1/{pBd} pT=1/{pTd}")LikeLike
Frits 1:18 pm on 4 February 2024 Permalink |
@Jim, as x >= k you can also start the “n” loop with 2 * k and remove the continue statement.
LikeLike
Jim Randell 1:50 pm on 4 February 2024 Permalink |
@Frits: Good point. I’ve got a much shorter program that uses some analysis to do without a loop for n at all. I’ll post it when I put the answer up.
LikeLike
Frits 2:36 pm on 4 February 2024 Permalink |
Yes, I have done the (probably same) analysis to get rid of a loop (the program is on PuzzlingInPython).
I try to alternate posting between your and Brian’s site.
LikeLike