Sunday Times Teaser 3061 – Ratio
by Andrew Skidmore
Published Sunday May 23 2021 (link)
Liam has split a standard pack of 52 cards into three piles; black cards predominate only in the second pile. In the first pile the ratio of red to black cards is 3 to 1. He transfers a black card from this pile to the second pile; the ratio of black to red cards in the second pile is now 2 to 1. He transfers a red card from the first pile to the third pile; the ratio of red to black cards in this pile is now a whole number to one.
Liam told me how many cards (a prime number) were initially in one of the piles; if I told you which pile you should be able to solve this teaser.
How many cards were initially in the third pile?
2 Comments
Leave one →
-
Brian Gladman permalink12345678910111213141516171819202122232425262728293031323334353637383940414243# the set of primes less than 52pr = {2, 3, 5, 7}pr = pr | {x for x in range(11, 53, 2) if all(x % p for p in pr)}sol = []# the red / black card ratio in pile one is 3 / 1for b1 in range(1, 7):r1 = 3 * b1# there are less red than black cards in pile twofor b2 in range(1, 26 - b1):for r2 in range(1, min(b2, 26 - r1)):# after adding a black card, the red / black# card ratio in pile two is 2 / 1if b2 + 1 == 2 * r2:# cards in pile three (black cards not predominant)b3, r3 = 26 - (b1 + b2), 26 - (r1 + r2)if r3 >= b3:# after adding a red card, the red / black card# ratio in pile three is m / 1 (m integer)m, r = divmod(r3 + 1, b3)if r == 0:# store all solutions where one pile# has a prime total number of cardst = ((r1, b1), (r2, b2), (r3, b3))if any(r + b in pr for r, b in t):sol.append(t)# look for a pile that gives a unique solutionfor pile in range(3):ss = []for s in sol:if sum(s[pile]) in pr:ss.append(s)if len(ss) == 1:if not r:t = ', '.join(f'<{r}r, {b}b>' for r, b in ss[0])print(f"Pile 3 has {sum(ss[0][2])} cards (piles = {t}).")
-
GeofffR permalink123456789101112131415161718192021222324252627282930313233343536373839404142from itertools import productfrom number_theory import is_primesol = []# red cards are (r1, r2, r3) in three card piles# black cards are (b1, b2, b3) in three card pilesfor p in product(range(1, 26), repeat=4):r1, r2, b1, b2 = pr3 = 26 - (r1 + r2)b3 = 26 - (b1 + b2)if r3 < 1 or b3 < 1:continue# the 1st pile of cards has red:black in ratio 3:1if r1 != 3 * b1:continue# in the 2nd pile, black cards predominate and the# red:black ratio is 2:1 after one black is addedif b2 <= r2 or b2 + 1 != 2 * r2:continue# reds predominate in the 3rd pileif r3 <= b3:continue# 3rd pile has a red:black ratio of m:1 with m an integerm, r = divmod(r3 + 1, b3)if not r and m > 1:s = ((r1, b1), (r2, b2), (r3, b3))sol.append(s)# find the unique prime number pile of cardsfor p in range(3):sv = []for s in sol:if is_prime(sum(s[p])):sv.append(s)if len(sv) == 1:print(f"There are {sum(sv[0][2])} cards in the 3rd pile.")print(f"Red/Black cards in the three piles are {sv[0]}")