Teaser 2930: Odd socks
From The Sunday Times, 18th November 2018 [link] [link]
I had a drawer containing some black socks and some white socks. If I drew out two socks at random the chance of getting a black pair was 1 in __.
After many washes all the socks looked grey. So I added some red socks to the drawer. Then if I drew out two at random the chance of getting a grey pair was 1 in __.
After many washes all the socks looked pink. So I added some green socks to the drawer. Then if I drew out two the chance of getting a pink pair was 1 in __.
After many washes all the socks looked brown. So I have now added some yellow socks to the drawer giving me a total of fewer than fifty socks. Now if I draw out two the chance of getting a brown pair is 1 in __.
The gaps above consist of four different prime numbers.
If I draw out two socks at random, what is the chance of getting a yellow pair?
[teaser2930]
Jim Randell 8:41 am on 25 March 2019 Permalink |
This Python 3 program works by finding possible (prime, X, Y) tuples for choosing a pair of X socks from X+Y, and then links together the appropriate number of tuples to solve the puzzle.
It runs in 75ms.
Run: [ @replit ]
from enigma import (irange, is_prime, fraction, printf) # min and max (m, M) = (2, 49) # find primes of the form (X + Y)(X + Y - 1) / X(X - 1) # where X + Y =< M and X >= m, Y >= m rs = list() for X in irange(max(m, 2), M - m): for Y in irange(m, M - X): (p, r) = divmod((X + Y) * (X + Y - 1), X * (X - 1)) if not (r == 0 and is_prime(p)): continue rs.append((p, X, Y)) # solve for k steps def solve(k, ns=None, ps=None): # are we done? if k == 0: yield (ns, ps) else: if not ns: # first step, use both X and Y for (p, X, Y) in rs: yield from solve(k - 1, [X, Y], [p]) else: # subsequent steps match sum on X T = sum(ns) for (p, X, Y) in rs: if X == T and p not in ps: yield from solve(k - 1, ns + [Y], ps + [p]) # find a sequence of 4 primes for ((B, W, R, G, Y), (p1, p2, p3, p4)) in solve(4): # calculate the probability of a yellow pair T = B + W + R + G + Y (a, b) = fraction(Y * (Y - 1), T * (T - 1)) # output solution printf("P(yellow) = {a}/{b} [B={B} W={W}, p1={p1}; R={R} p2={p2}; G={G} p3={p3}; Y={Y} p4={p4}; T={T}]")Solution: There is a 1 in 6 chance of getting a yellow pair.
There are two scenarios which give the answer:
But in both cases the probability of a yellow pair (from 21 brown and 15 yellow) is 1/6.
In the puzzle I interpreted “some” to mean “at least 2”, and this gives the solution above. However, if we interpret it as “at least 1” then you get 2 further solutions, which give an answer of 1/14. (You can change the value of [[
m]] to [[1]] in the program to see this).Interestingly there are no solutions (even with the relaxation of “some”) where all the numbers of different coloured socks are all even. Which certainly is an “odd” way to acquire socks.
LikeLike