# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1144: Isaac Newton (?-1727)

From New Scientist #2300, 21st July 2001 [link]

Isaac Newton, 1642-1727? or 1643-1727? The discrepancy of course is due to the overlap of the Julian and Gregorian calendars and to avoid any controversy I have omitted his birth year altogether in the given multiplications, leaving only 1727 as shown. All other digits have been replaced by letters and asterisks.

However, the mechanistic laws of motion attributed to this great scientists provide another clue and this is given by the simple equation: F = m × A.

In the multiplications and the clue, different capital letters stand for different digits and the same capital letter stands for the same digit. Asterisks and the lower-case letter, m, can be any digit.

What is the value of SCIENTIST?

[enigma1144]

### 3 responses to “Enigma 1144: Isaac Newton (?-1727)”

1. Jim Randell 24 October 2016 at 8:27 am

We can use the general Alphametic solver (SubstitutedExpression()) from the enigma.py library to solve this puzzle without having to write a program. We introduce additional (lower-case) symbols for the multiplicands of the sum using the --symbols=<string> parameter (so the first sum is abc × def and the second sum is ghi × kl7), and we allow these to take on any value, by using the --distinct=<string> parameter to select only the upper-case letters.

We then construct expressions for the intermediate products. In the first sum, we are only interested in the fact that each has exactly three digits. In the second sum the expressions are a little more complicated.

Here is the command and its (quite verbose) output. It runs in 147ms.

```% python -m enigma SubstitutedExpression \
--symbols="ACEFINOSTWabcdefghiklm" --distinct="ACEFINOSTW" \
"abc * def = ISAAC" \
"99 < abc * f < 1000" \
"99 < abc * e < 1000" \
"99 < abc * d < 1000" \
"ghi * (10 * kl + 7) = NEWTON" \
"999 < ghi * 7 < 10000" "((ghi * 7) // 10) % 10 = 2" \
"99 < ghi * l < 1000" "((ghi * l) // 10) % 10 = 7" \
"999 < ghi * k < 10000" "((ghi * k) // 10) % 10 = 1" \
"m * A = F"
(abc * def = ISAAC) (99 < abc * f < 1000) (99 < abc * e < 1000) (99 < abc * d < 1000) (ghi * (10 * kl + 7) = NEWTON) (999 < ghi * 7 < 10000) (((ghi * 7) // 10) % 10 = 2) (99 < ghi * l < 1000) (((ghi * l) // 10) % 10 = 7) (999 < ghi * k < 10000) (((ghi * k) // 10) % 10 = 1) (m * A = F)
(215 * 323 = 69445) (99 < 215 * 3 < 1000) (99 < 215 * 2 < 1000) (99 < 215 * 3 < 1000) (389 * (10 * 82 + 7) = 321703) (999 < 389 * 7 < 10000) (((389 * 7) // 10) % 10 = 2) (99 < 389 * 2 < 1000) (((389 * 2) // 10) % 10 = 7) (999 < 389 * 8 < 10000) (((389 * 8) // 10) % 10 = 1) (2 * 4 = 8) / A=4 C=5 E=2 F=8 I=6 N=3 O=0 S=9 T=7 W=1 a=2 b=1 c=5 d=3 e=2 f=3 g=3 h=8 i=9 k=8 l=2 m=2 / 956237697
SCIENTIST = 956237697 [1 solution]
```

Solution: SCIENTIST = 956237697.

(And NEW = 321).

The full multiplication sums are:

And the solution for F = m × A is 8 = 2 × 4.

To make things easier you can put all the command line arguments to enigma.py into a file (with “shell-like” syntax) and then use the -r / --run command-line argument to execute the solver.

For example if the following is saved to a file called enigma1144.run

```# use the alphametic solver
SubstitutedExpression

# solver parameters
--symbols="ACEFINOSTWabcdefghiklm"
--distinct="ACEFINOSTW"

# expressions to solve
"abc * def = ISAAC"
"99 < abc * f < 1000"
"99 < abc * e < 1000"
"99 < abc * d < 1000"
"ghi * (10 * kl + 7) = NEWTON"
"999 < ghi * 7 < 10000" "((ghi * 7) // 10) % 10 = 2"
"99 < ghi * l < 1000" "((ghi * l) // 10) % 10 = 7"
"999 < ghi * k < 10000" "((ghi * k) // 10) % 10 = 1"
"m * A = F"
```

Then we can just run the command: python -m enigma -r enigma1144.run, as follows:

```% python -m enigma -r enigma1144.run
(abc * def = ISAAC) (99 < abc * f < 1000) (99 < abc * e < 1000) (99 < abc * d < 1000) (ghi * (10 * kl + 7) = NEWTON) (999 < ghi * 7 < 10000) (((ghi * 7) // 10) % 10 = 2) (99 < ghi * l < 1000) (((ghi * l) // 10) % 10 = 7) (999 < ghi * k < 10000) (((ghi * k) // 10) % 10 = 1) (m * A = F)
(215 * 323 = 69445) (99 < 215 * 3 < 1000) (99 < 215 * 2 < 1000) (99 < 215 * 3 < 1000) (389 * (10 * 82 + 7) = 321703) (999 < 389 * 7 < 10000) (((389 * 7) // 10) % 10 = 2) (99 < 389 * 2 < 1000) (((389 * 2) // 10) % 10 = 7) (999 < 389 * 8 < 10000) (((389 * 8) // 10) % 10 = 1) (2 * 4 = 8) / A=4 C=5 E=2 F=8 I=6 N=3 O=0 S=9 T=7 W=1 a=2 b=1 c=5 d=3 e=2 f=3 g=3 h=8 i=9 k=8 l=2 m=2 / 956237697
SCIENTIST = 956237697 [1 solution]
```

(I know this works on Unix-like systems such as Linux and Mac OS X (or macOS as we are supposed to call it now). I’d be interested in reports from other systems).

In fact on a Unix-like system, you can put the command in the first line of the file (preceded by the special characters #!), and execute the file directly (by making it executable).

So we would add the following line at the top of enigma1144.run

```#!/usr/bin/env python -m enigma -r
```

Make sure the file is executable (using: % chmod a+x enigma1144.run), and then we can run it directly from the shell:

```% ./enigma1144.run
(abc * def = ISAAC) (99 < abc * f < 1000) (99 < abc * e < 1000) (99 < abc * d < 1000) (ghi * (10 * kl + 7) = NEWTON) (999 < ghi * 7 < 10000) (((ghi * 7) // 10) % 10 = 2) (99 < ghi * l < 1000) (((ghi * l) // 10) % 10 = 7) (999 < ghi * k < 10000) (((ghi * k) // 10) % 10 = 1) (m * A = F)
(215 * 323 = 69445) (99 < 215 * 3 < 1000) (99 < 215 * 2 < 1000) (99 < 215 * 3 < 1000) (389 * (10 * 82 + 7) = 321703) (999 < 389 * 7 < 10000) (((389 * 7) // 10) % 10 = 2) (99 < 389 * 2 < 1000) (((389 * 2) // 10) % 10 = 7) (999 < 389 * 8 < 10000) (((389 * 8) // 10) % 10 = 1) (2 * 4 = 8) / A=4 C=5 E=2 F=8 I=6 N=3 O=0 S=9 T=7 W=1 a=2 b=1 c=5 d=3 e=2 f=3 g=3 h=8 i=9 k=8 l=2 m=2 / 956237697
SCIENTIST = 956237697 [1 solution]
```
2. Brian Gladman 25 October 2016 at 9:14 pm

I thought that this was going to be quite slow but it isn’t because the individual products are stll heavily constrained even when considered independently (where the right hand product has only a single solution).

```from itertools import product
from functools import reduce

# compile the set of solutions for the left hand product
# ensuring that all partial products have three digits
sol_l = set()
for top in range(100, 1000):
for b0 in range(1, 10):
pp0 = b0 * top
if not 100 <= pp0 < 1000:
continue

for b1 in range(1, 10):
pp1 = b1 * top
if not 100 <= pp1 < 1000:
continue

for b2 in range(1, 10):
pp2 = b2 * top
if not 100 <= pp2 < 1000:
continue

# ensure that ISAAC has the correct form and, since
# F = m * A < 10 for some m > 1, that 0 < A < 5
isaac = 100 * pp2 + 10 * pp1 + pp0
if not isaac >= 100000:
i, s, a, _a, c = li = [int(x) for x in str(isaac)]
if 0 < a < 5 and _a == a and len(set(li)) == 4:
sol_l.add((top, 100 * b2 + 10 * b1 + b0, frozenset(li), a))

# compile the set of solutions for the right hand product
# ensuring that the partial products have the given forms
sol_r = set()
for top in range(100, 1000):
pp0 = 7 * top
if pp0 < 1000 or (pp0 % 100) // 10 != 2:
continue

for b1 in range(1, 10):
pp1 = b1 * top
if not 100 <= pp1 < 1000 or (pp1 % 100) // 10 != 7:
continue

for b2 in range(1, 10):
pp2 = b2 * top
if pp2 < 1000 or (pp2 % 100) // 10 != 1:
continue

# ensure that NEWTON has the correct form
newton = 100 * pp2 + 10 * pp1 + pp0
n, e, w, t, o, _n = li = [int(x) for x in str(newton)]
if _n == n and len(set(li)) == 5:
sol_r.add((top, 100 * b2 + 10 * b1 + 7, frozenset(li)))

# now consider all possible pairs of solutions for the two products
for (tl, bl, sl, a), (tr, br, sr) in product(sol_l, sol_r):

# they must not share any digits as they don't share any letters
if not sl & sr:
# find F and check that F = m * A for some m > 1
f, = set(range(10)).difference(sl | sr)
m, r = divmod(f, a)
if m > 1 and not r:

# form a map from letters to digits
li = [int(x) for x in str(tl * bl) + str(tr * br)]
d = dict(zip('ISA_CNEWTO_', li))
# and use it to compose SCIENTIST
sc = reduce(lambda x, y: 10 * x + y, [d[c] for c in 'SCIENTIST'])
fs = '{} x {} = {}, {} x {} = {}, SCIENTIST = {}.'
print(fs.format(tl, bl, tl * bl, tr, br, tr * br, sc))
```
3. geoffrounce 13 May 2018 at 3:44 pm
```% A Solution in MiniZinc
include "globals.mzn";

%      a b c        g h i
%      d e f        j k 7
%    -------      -------
%      * * *      * * 2 *  (line 4) - 2nd sum
%    * * *        * 7 *    (line 5) - 2nd sum
%  * * *      * * 1 *      (line 6) - 2nd sum
%  ---------  -----------
%  I S A A C  N E W T O N
%  ---------  -----------

var 0..9:I; var 0..9:S; var 0..9:A; var 0..9:C;
var 0..9:N; var 0..9:E; var 0..9:W; var 0..9:T;
var 0..9:O; var 2..9:F;

constraint all_different ( [I, S, A, C, N, E, W, T, O, F] );

var 0..9:a; var 0..9:b; var 0..9:c;
var 0..9:d; var 0..9:e; var 0..9:f;
var 0..9:g; var 0..9:h; var 0..9:i;
var 0..9:j; var 0..9:k; var 1..9:m;

var 100..999: abc = 100*a + 10*b + c;
var 100..999: def = 100*d + 10*e + f;

constraint I > 0 /\ N > 0 /\ A > 0 /\ a > 0 /\ d > 0;

% sum 1 - multiplication line results are line1,line2 and line3
var 100..999: line1;
var 1000..9999: line2;
var 10000..99999: line3;

var 10000..99999: ISAAC = 10000*I + 1000*S + 110*A + C;
var 100000..999999: NEWTON = 100000*N + 10000*E + 1000*W + 100*T + 10*O + N;

% 1st sum
constraint abc * def == ISAAC;
constraint f * abc == line1;
constraint e * 10 * abc = line2;
constraint d * 100 * abc = line3;

constraint line2 mod 10 == 0;
constraint line3 div 10 mod 10 == 0 /\ line3 mod 10 == 0;

% 2nd sum - multiplication line results are line4, line5, and line6
var 100..999: ghi = 100*g + 10*h + i;
var 100..999: jk7 = 100*j + 10*k + 7;

constraint g > 0 /\ j > 0;

var 1000..9999: line4;
var 1000..9999: line5;
var 100000..999999: line6;

constraint ghi * jk7 == NEWTON;
constraint 7 * ghi == line4;
constraint line4 div 10 mod 10 == 2;

constraint k * 10 * ghi == line5;
constraint line5 div 100 mod 10 == 7;
constraint line5 mod 10 == 0;

constraint j * 100 * ghi == line6;
constraint line6  div 1000 mod 10 == 1;
constraint line6 div 10 mod 10 == 0;
constraint line6 mod 10 == 0;

% Extra Newton's 2nd Law constraint
constraint F = m * A;

solve satisfy;

output [ "ISAAC = " ++ show(ISAAC) ++ "\n" ++
"NEWTON = " ++ show(NEWTON) ++ "\n" ++"SCIENTIST = " ++
show(S),show(C),show(I),show(E),show(N),show(T),show(I),show(S),show(T)];

% ISAAC = 69445
% NEWTON = 321703
% SCIENTIST = 956237697
% ----------
% Finished in 127msec (Chuffed Solver)
```

This site uses Akismet to reduce spam. Learn how your comment data is processed.