Teaser 2722: A simple sum
From The Sunday Times, 23rd November 2014 [link]
I have written down two three-figure numbers and one four-figure number: between them they use each of the digits 0 to 9 exactly once. In fact the four-figure number is the sum of the other two numbers.
If I told you how many of the three numbers were even, then it would be possible to work out the four-figure number.
What is it?
[teaser2722]
Jim Randell 10:24 am on 17 March 2022 Permalink |
This Python program uses the [[
SubstitutedExpression]] solver, from the enigma.py library, to find possible sums, and then the [[filter_unique]] function to find those that give a unique result if we know the number of even numbers involved.It runs in 58ms.
Run: [ @replit ]
from enigma import (SubstitutedExpression, filter_unique, unpack, multiset, printf) # find viable alphametic sums p = SubstitutedExpression.split_sum( "ABC + DEF = GHIJ", extra=["A < D"], # remove duplicates answer="(ABC, DEF, GHIJ)", ) # if we knew how many of the numbers were even, we could work out the result rs = filter_unique( p.answers(verbose=0), (lambda ns: sum(n % 2 == 0 for n in ns)), unpack(lambda x, y, z: z), ) # output possible sums m = multiset() for (x, y, z) in rs.unique: printf("[{x} + {y} = {z}]") m.add(z) # output solution for (v, n) in m.most_common(): printf("result = {v} [{n} sums]")Solution: The result of the sum is 1098.
There are 4 possible sums:
(And another 4 where the summands are swapped around).
LikeLike
Hugh+Casement 8:58 am on 18 March 2022 Permalink |
Either all three numbers are even, or only one of them is.
If just one of the three-digit numbers is even, there are 24 possible sets,
with sum 1035, 1053, 1305, 1503, or 1089.
If only the four-digit number is even, there are 20 possible sets,
with sum 1026, 1062, 1206, 1602, or 1098.
Only if both three-digit numbers are even do we have a unique sum.
LikeLike
GeoffR 2:59 pm on 18 March 2022 Permalink |
A MiniZinc program does indeed confirm that two even numbers are required to sum to a unique four digit number.
LikeLike