Here is how Mathematica can be used to solve New Scientist Enigma number 1458 in the 1 September 2007 issue.
Define the digits used in the 7-digit number.
u = {n6, n5, n4, n3, n2, n1, n0};
Define the reordered digits used in the 6-digit number.
v = {n0, n1, n2, n3, n5, n4};
Define the 7-digit number.
a = FromDigits[u] // Expand
n0 + 10 n1 + 100 n2 + 1000 n3 + 10000 n4 + 100000 n5 + 1000000 n6
Define the 6-digit number.
b = FromDigits[v] // Expand
100000 n0 + 10000 n1 + 1000 n2 + 100 n3 + n4 + 10 n5
Define some inequality constraints on the digits.
c = Apply[And, Map[0 <= # <= 9 &, u]]
0 <= n0 <= 9 && 0 <= n1 <= 9 && 0 <= n2 <= 9 && 0 <= n3 <= 9 && 0 <= n4 <= 9 && 0 <= n5 <= 9 && 0 <= n6 <= 9
Find solutions for the digits in the domain of integers. Searching for 3 solutions and finding only 2 demonstrates that there are only 2 solutions, one of which is the trivial solution with all digits zero.
s = FindInstance[a == 3 b && c, u, Integers, 3]
{{n6->0, n5->0, n4->0, n3->0, n2->0, n1->0, n0->0}, {n6->2, n5->9, n4->3, n3->9, n2->9, n1->7, n0->9}}
Verify the 2 solutions.
a == 3 b /. s
{True, True}
No comments:
Post a Comment