Teaser 2872: Appropriate arithmetic
From The Sunday Times, 8th October 2017 [link] [link]
I wrote down three two-figure numbers, one of which was double one of the others. Overall the three numbers used six consecutive digits between them. I then added up the three numbers to give a three-figure sum, and I also multiplied together the three numbers to give a five-figure product. Replacing digits consistently by letters my two answers, appropriately, were ADD and TIMES.
What were the three original numbers?
[teaser2872]
Jim Randell 9:11 am on 10 February 2022 Permalink |
If we suppose the three numbers are ab, cd, ef, and that 2 × ab = cd then we have:
And we can use the [[
SubstitutedExpression]] solver from the enigma.py library to solve the alphametic expressions.The following run file executes in 59ms (the generated program has an internal runtime of 575µs).
Run: [ @replit ]
#! python3 -m enigma -rr SubstitutedExpression --symbols="ADEIMSTabcdef" --distinct="ADEIMST,abcdef" --answer="(ab, cd, ef)" # cd is twice ab "2 * ab = cd" # sum is ADD, product is TIMES "ab + cd + ef = ADD" "ab * cd * ef = TIMES" # a, b, c, d, e, f are 6 consecutive digits --code="is_consecutive = lambda *vs: all(y == x + 1 for (x, y) in tuples(ordered(*vs), 2))" "is_consecutive({a}, {b}, {c}, {d}, {e}, {f})" # [optional] --template="(ab + cd + ef = ADD) (ab * cd * ef = TIMES)" --solution=""Solution: The three original numbers are: 23, 46, 75.
LikeLike
Frits 1:17 pm on 10 February 2022 Permalink |
Instead of the all(…) condition you can also use:
"(s := sorted([{a}, {b}, {c}, {d}, {e}, {f}]))[-1] - s[0] == 5"or
"max(s := [{a}, {b}, {c}, {d}, {e}, {f}]) - min(s) == 5"LikeLike
GeoffR 3:07 pm on 10 February 2022 Permalink |
Using Frits second suggestion proved useful in a MiniZinc solution.
LikeLike