Sunday Times Teaser 2554 – Odd and Even
by Graham Smithers
Published: 4 September 2011 (link)
Roddy and Eve have a set of cards on which is written a consecutive sequence of whole numbers, one number on each card. Roddy challenges Oliver to choose two cards at random, promising a prize if the sum of the numbers is odd. Eve issues the same challenge, but offers a prize for an even sum. Oliver accepts the challenge that gives him the greater probability of winning. This probability is a whole number percentage and, when reversed, it gives the two-figure number of cards.
Whose challenge did Oliver accept and how many cards are there?
One Comment
Leave one →
-
Brian Gladman permalink12345678910111213141516171819202122232425from fractions import Fraction as RF# the probability that two numbers chosen randomly from# 'e' even and 'o' odd numbers will have an odd sumdef prob(e, o):return RF(2 * e * o, (e + o) * (e + o - 1))# the number of numbers (cards)for n in range(10, 100):# find the probability of an odd sum with this number# of numberspo = prob(n // 2, n - n // 2)# choose the higher probability between an even and# an odd sumpc = max(po, 1 - po)# now check for a number of numbers and a percentage# probabilty with the same two digits but reversedif 100 * pc == 10 * (n % 10) + n // 10:print('Oliver accepted the {} challenge with {} cards.'.format('odd' if pc == po else 'even', n))