# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1602: Miscount

From New Scientist #2767, 3rd July 2010 [link]

I have assigned a whole number to each letter of the alphabet. These numbers are not necessarily different and they include negatives and zero. With these numbers I found that

O + N + E = 1

T + W + O = 2

T + H + R + E + E = 3

and so on all the way up to

T + W + E + N + T + Y + N + I + N + E = 29.

Unfortunately, I now find that I made one slip in my additions. Just one of my 29 equations was wrong.

Which equation is wrong?

What should the sum of the letters equal in that case?

[enigma1602]

### 3 responses to “Enigma 1602: Miscount”

1. jimrandell 9 January 2012 at 4:45 pm

This is a tricky one to solve programatically. With a bit of logic and some tussling with simultaneous equations this is easy to solve on paper. I toyed with the idea of writing code to solve the (simplified) simultaneous equations in this problem, and then I found the marvellous SymPy library, which can do all this and more. It feels a bit like using a sledgehammer to crack a nut, but here it is.

It’s Python2.7 code (SymPy wouldn’t install on my Python3.2 installation), and it runs in 3.7s. If you’re willing to accept the logic that equations (1)-(9),(20)-(29) and (14),(16),(17),(19) must all be correct, you can get the runtime down to less than 1s.

```from sympy import solve, sympify

# use lower case to avoid namespace clashes
words = ( None,
'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen',
'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty', 'twentyone',
'twentytwo', 'twentythree', 'twentyfour', 'twentyfive', 'twentysix',
'twentyseven', 'twentyeight', 'twentynine' )

# create a list of equations (indexed from 1)
equations = list('+'.join(list(words[i])) + '-' + str(i) for i in range(1, 30))
equations.insert(0, None)

for i in range(1, 30):
# make a new list of equations, without equation i
e = list(equations)
e.pop(i)
# attempt to solve the equations
for s in solve(e[1:], dict=True):
# check for solutions that are non-integer
if any(v.is_number and not v.is_integer for v in s.values()): continue
# what should the incorrect equation be?
w = words[i]
v = sum(s[sympify(x)] for x in list(w))
print(' + '.join(list(w.upper())), '=', v)
```

Solution: T + H + I + R + T + E + E + N = 2.

2. geoffrounce 23 August 2016 at 4:15 pm

I did a full solution in MiniZinc, giving the answer that the 13th equation was incorrect.
I found two sets of letter values which gave the same solution.

I checked all the 29 equations with the first set of letter values and they were all correct, except for the 13 th equation The programme found the 2 sets of letter values (giving the same answer) in 798 msec.

```% A Solution in MiniZinc
include "globals.mzn";

set of int: Domain = -30..30;

var Domain: O; var Domain: N; var Domain: E;
var Domain: T; var Domain: W; var Domain: H;
var Domain: R; var Domain: F; var Domain: U;
var Domain: I; var Domain: V; var Domain: S;
var Domain: X; var Domain: G; var Domain: L;
var Domain: Y;

% letter variables used in the equations
array[1..16] of var int: y = ([O,N,E,T,W,H,R,F,U,I,V,S,X,G,L,Y]);

array[1..29] of var Domain: x =
[O+N+E, T+W+O, T+H+R+E+E, F+O+U+R, F+I+V+E, S+I+X, S+E+V+E+N,
E+I+G+H+T, N+I+N+E, T+E+N, E+L+E+V+E+N, T+W+E+L+V+E,
T+H+I+R+T+E+E+N, F+O+U+R+T+E+E+N, F+I+F+T+E+E+N,
S+I+X+T+E+E+N, S+E+V+E+N+T+E+E+N, E+I+G+H+T+E+E+N, N+I+N+E+T+E+E+N,
T+W+E+N+T+Y, T+W+E+N+T+Y+O+N+E, T+W+E+N+T+Y+T+W+O, T+W+E+N+T+Y+T+H+R+E+E,
T+W+E+N+T+Y+F+O+U+R, T+W+E+N+T+Y+F+I+V+E, T+W+E+N+T+Y+S+I+X,
T+W+E+N+T+Y+S+E+V+E+N, T+W+E+N+T+Y+E+I+G+H+T, T+W+E+N+T+Y+N+I+N+E];

% exactly one of the 29 equations is wrong
constraint sum(i in 1..29)(bool2int(x[i] != i)) = 1;

solve satisfy;

output [ "Array of totals for 29 equations is " ++ show(x) ++
"\nVariable values used = " ++ show(y) ];

% Array of totals for 29 equations is [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
% 12, 2, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]

% Variable values used = [-9, 10, 0, 0, 11, -11, 14, 8, -9, -11, 8, -11,
% 28, 30, -7, -1] - 1st solution for letter values
%
% Ans:  T + H + I + R + T + E + E + N = 2 is the incorrect equation (should be 13)
%
% Letter Values
% -------------
% 1st set of  values  =  [-9, 10, 0, 0, 11, -11, 14, 8, -9, -11, 8, -11, 28, 30, -7, -1]
% array y letters =      [ O, N,  E, T,  W,  H,  R,  F,  U,  I,  V,  S,  X,  G,   L,  Y]
% or 2nd set of values = [-9, 10, 0, 0, 11, -9,  12, 8, -7, -11, 8, -11, 28, 28, -7, -1]
%
```
3. Jim Randell 24 August 2016 at 10:02 am

Twelve of the letters have fixed values, but the values of the remaining four letters cannot be determined.

So, we have:

E = 0
F = 8
I = −11
L = −7
N = 10
O = −9
S = −11
T = 0
V = 8
W = 11
X = 28
Y = −1

But the remaining letters can take on any value that satisfies the following parameterisation for any integer k:

G = 21 − k
H = k − 2
R = 5 − k
U = k

In the equations given in the question the coefficients of k always cancel out, so its value cannot be determined.

This also shows that we cannot extend the problem to T + H + I + R + T + Y as this sum has a value of −9. But by assigning a value of Z = k + 4 we could have Z + E + R + O = 0.

Setting k = −37 sets the value of R = 42 and allows the equations for 40 – 49 to work, but the other numbers from 30 – 99 all have values that are independent of k, and none of them work correctly.

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