Brain-Teaser 23: [Money sharing]
From The Sunday Times, 27th August 1961 [link]
A man divided 8s. 4d. among his three sons so that the difference between the shares of the eldest and youngest, expressed in halfpence, was a perfect square. The total of Alan’s and Bob’s shared was an exact multiple of 5½d.; the total of Bob’s and Clive’s shares an exact multiple of 6½d.; and the total of Alan’s and Clive’s shares an exact multiple of 9½d.
What was the name of the second son, and what was his share?
This puzzle was originally published with no title.
[teaser23]
Jim Randell 8:55 am on 21 February 2021 Permalink |
1s = 12d.
Working in half-pennies (hp) the total amount to distribute is 100 d = 200 hp.
And we are told:
And the difference between two of the numbers is a square number of half pennies.
The following Python program runs in 53ms.
Run: [ @repl.it ]
from enigma import irange, is_square, div, printf # solve the equations def solution(middle, AB, AC, BC): A = div(AB + AC - BC, 2) B = div(AB + BC - AC, 2) C = div(AC + BC - AB, 2) if not any(x is None or x < 0 for x in (A, B, C)): # output solution printf("A={A} hp, B={B} hp, C={C} hp; middle = {middle}") # A + C is some multiple of 19 for AC in irange(19, 200, step=19): # B + C is some multiple of 13 for BC in irange(13, 200, step=13): # A + B is some multiple of 11 # and (A + B) + (B + C) + (A + C) = 2(A + B + C) = 400 AB = 400 - (AC + BC) if AB % 11 > 0: continue # one of the differences is a square # B - C = (A + B) - (A + C) if is_square(abs(AB - AC)): solution('A', AB, AC, BC) # A - C = (A + B) - (B + C) if is_square(abs(AB - BC)): solution('B', AB, AC, BC) # A - B = (A + C) - (B + C) if is_square(abs(AC - BC)): solution('C', AB, AC, BC)Solution: The middle son was Clive. His share was 45d = (3s 9d).
The shares are:
And we see:
And the difference between the eldest and the youngest is: B − A = 10² hp.
LikeLike
Frits 11:53 am on 21 February 2021 Permalink |
from enigma import SubstitutedExpression, is_square, peek # the alphametic puzzle p = SubstitutedExpression( [# A = AST, B = BVW, C = CYZ # start with the most restrictive constraint # A + C is some multiple of 19 "(AST + CYZ) % 19 == 0", # divide 200 half-pennies over 3 sons "200 - AST - CYZ = BVW", # B + C is some multiple of 13 "(BVW + CYZ) % 13 == 0", # A + B is some multiple of 11 "(AST + BVW) % 11 == 0", # difference between the eldest and youngest was a perfect square "peek(2 - i for (i, (x, y)) in \ enumerate(zip([AST, CYZ, BVW], [BVW, AST, CYZ])) \ if is_square(abs(x - y))) = I", ], answer="I, [AST, BVW, CYZ][I]", d2i=dict([(2, "ABC")] + [(k, "ABCI") for k in range(3, 10)]), distinct="", reorder=0, verbose=0) for (_, ans) in p.solve(): print(f"{['Alan', 'Bob', 'Clive'][ans[0]]} with share {ans[1]} half-pennies")LikeLike
Jim Randell 12:49 pm on 21 February 2021 Permalink |
Here’s an alternative solution using the [[
SubstitutedExpression()]] solver:from enigma import (SubstitutedExpression, subsets, is_square, printf) # find candidate (A, B, C) values p = SubstitutedExpression( [ "A + B + C == 200", "(A + B) % 11 = 0", "(B + C) % 13 = 0", "(A + C) % 19 = 0" ], base=201, distinct=(), answer="(A, B, C)", template="", ) # look at possible (A, B, C) values for (_, vs) in p.solve(verbose=0): # the values for the eldest and youngest differ by a square number for ((i, x), (j, y)) in subsets(enumerate(vs), size=2): if is_square(abs(x - y)): # identify the middle son m = "ABC"[3 - i - j] printf("A={vs[0]} hp, B={vs[1]} hp, C={vs[2]} hp; middle={m}")LikeLike
Hugh Casement 1:51 pm on 21 February 2021 Permalink |
Theoretically Alan and Clive could each have received 57 ha’pence and Bob 86.
Zero is also a square number! However, I doubt that is the intended solution.
LikeLike
Jim Randell 2:02 pm on 21 February 2021 Permalink |
@Hugh: Well spotted!
In my programs, both
0andNoneevaluate to false, so using the return value from [[is_square()]] as a boolean value will reject 0. (It also doesn’t consider 0 to be allowed as a multiple of 11, 13, 19).You can explicitly check [[
is_square(...) is not None]], or just import [[is_square_p()]] instead which returns a boolean.And if you do that you do indeed get two solutions:
The published solution is: “Clive, 3s 9d”.
Perhaps the setter intended the shares to be three different values.
LikeLike
John Crabtree 6:58 pm on 22 February 2021 Permalink |
Working in 1/2d, then A + B + C = 200
A + B = 11p, p ≤ 18
B + C = 13q, q ≤ 15
A + C = 19r, r ≤ 10
Summing the three gives 400 = 11p + 13q + 19r
Using r as a variable as it has the fewest possible values:
B = 200 – 19r, p = 8 + 3r mod 13, q = 3 + 7r mod 11 which leads to
A = 31 + 52r mod 143
C = 112 + 110r mod 143
It is then straightforward to manually generate a table of values for A, B and C for each r. r = 1, 2 and 4 give A+B+C = 343. r = 3 and r = 5 to 10 give A+B+C = 200 and include the two solutions noted by Jim.
LikeLike