Teaser 2943: Keep your balance
From The Sunday Times, 17th February 2019 [link] [link]
George and Martha have a set of a dozen balls, identical in appearance but each has been assigned a letter of the alphabet, A, B, …, K, L and each is made of a material of varying density so that their weights in pounds are 1, 2…. 11, 12 but in no particular order. They have a balance and the following weighings were conducted:
(1) {A, C, I} vs {G, J, L}
(2) {A, H, L} vs {G, I, K}
(3) {B, I, J} vs {C, F, G}
(4) {B, D, I} vs {E, G, H}
(5) {D, F, L} vs {E, G, K}
On all five occasions, there was perfect balance and the total of the threesome in each was a different prime number, that in (1) being the smallest and progressing to that in (5) which was the largest.
In alphabetical order, what were the weights of each of the twelve balls?
[teaser2943]
Jim Randell 8:38 am on 17 February 2019 Permalink |
We can solve this using the [[
SubstitutedExpression()]] solver from the enigma.py library. Treating each symbol as standing for a different non-zero base 13 digit.This run-file executes in 332ms.
Run: [ @replit ]
Solution: The weights of the balls are: A=4, B=8, C=5, D=9, E=12, F=11, G=1, H=6, I=2, J=7, K=10, L=3.
LikeLike
Jim Randell 10:19 am on 17 February 2019 Permalink |
There are six symbols in the first weighing, and together they must sum to twice the smallest prime, so the smallest possible value for the smallest prime is:
Similarly the largest possible value for the largest prime is:
So the list of possible primes is: 11, 13, 17, 19, 23.
There are only 5 primes on the list, so the weighings give us 10 equations in 12 variables.
Again using the [[
SubstitutedExpression()]] solver, this run file executes in 131ms.Run: [ @replit ]
LikeLike
Jim Randell 7:30 am on 5 March 2019 Permalink |
Here’s a manual solution:
Given the 10 equations above and adding the equation:
Gives us 11 equations in 12 variables.
These can be solved to give the other values in terms of B:
And all the variables have to take on different values from 1 to 12.
From I and E, we have:
So B is 7 or 8.
The formula for F gives:
The first of these is not possible so B = 8, giving:
LikeLike
Frits 3:43 pm on 30 July 2020 Permalink |
@Jim
“These can be solved to give the other values in terms of B:” –> easier said than done.
Can your Enigma functions generate these 11 equations in terms of B?
LikeLike
Jim Randell 5:03 pm on 30 July 2020 Permalink |
You could use SymPy to reduce the set of equations down using a single parameter.
But you can also choose a value for B and then you have 12 equations in 12 variables, which you can solve using the [[
Matrix.linear()]] solver in enigma.py.Run: [ @replit ]
from enigma import (Matrix, irange, join, printf) eqs = [ # A B C D E F G H I J K L ( 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), # B = ? ( 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0 ), # (A, C, I) = 11 ( 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 ), # (G, J, L) = 11 ( 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 ), # (A, H, L) = 13 ( 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0 ), # (G, I, K) = 13 ( 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 ), # (B, I, J) = 17 ( 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0 ), # (C, F, G) = 17 ( 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0 ), # (B, D, I) = 19 ( 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0 ), # (E, G, H) = 19 ( 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1 ), # (D, F, L) = 23 ( 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0 ), # (E, G, K) = 23 ( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ), # (A ... L) = 78 ] # the collection of weights weights = set(irange(1, 12)) # choose a value for B for B in weights: # evaluate the equations s = Matrix.linear(eqs, [B, 11, 11, 13, 13, 17, 17, 19, 19, 23, 23, 78]) # the answers should be the values in weights if not (set(s) == weights): continue # output solution printf("{s}", s=join((join((w, '=', v)) for (w, v) in zip("ABCDEFGHIJKL", s)), sep=" "))LikeLike
Frits 8:27 pm on 30 July 2020 Permalink |
Thanks, I ran the following code at [ https://live.sympy.org/ ]:
from sympy import linsolve, symbols, linear_eq_to_matrix A,B,C,D,E,F,G,H,I,J,K,L = symbols("A,B,C,D,E,F,G,H,I,J,K,L", integer=True) variables = [A,C,D,E,F,G,H,I,J,K,L,B] def my_solver(known_vals): eqns = [A + C + I - 11, G + J + L - 11, A + H + L - 13, G + I + K - 13, B + I + J - 17, C + F + G - 17, B + D + I - 19, E + G + H - 19, D + F + L - 23, E + G + K - 23, A + B + C + D + E + F + G + H + I + J + K + L - 78] # add the known variables to equation list for x in known_vals.keys(): eqns.append(x - (known_vals[x])) X, b = linear_eq_to_matrix(eqns, variables) solution = linsolve((X, b), variables) return solution my_solver({})Output:
LikeLike
GeoffR 3:38 pm on 19 February 2019 Permalink |
I assumed you did not want the answer shown?
LikeLike