# Enigmatic Code

Programming Enigma Puzzles

## Enigma 399: Time, gentlemen, please

From New Scientist #1549, 26th February 1987 [link]

The beer-mats at our local pub have puzzles on them. Here is one in which the digits are consistently replaced by letters.

BEER – MAT = TEST
NINE is a perfect square
IT is a number
THIS is odd!

[enigma399]

### 2 responses to “Enigma 399: Time, gentlemen, please”

1. Jim Randell 9 June 2017 at 9:54 am

We can use the SubstitutedExpression() solver from the enigma.py library to solve this puzzle.

The following run file executes in 87ms.

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

SubstitutedExpression

--invalid="0,STMBNI"
--invalid="2468,S"

"TEST + MAT = BEER"
"is_square(NINE)"
```

Solution: TIME = 5291.

There are two solutions to the alphametic sum as A and S are interchangeable:

5135 + 975 = 6110
5175 + 935 = 6110

In each case NINE = 8281 (= 91²).

2. geoffrounce 10 June 2017 at 9:41 am
```% A Solution in MiniZinc
include "globals.mzn";

var 1..9:T;  var 0..9:E;  var 1..9:S;  var 1..9:M;  var 0..9:A;
var 1..9:B;  var 0..9:R;  var 1..9:I;  var 1..9:N;
var 0..9:carry1; var 0..9:carry2; var 0..9:carry3;

constraint all_different ([T,E,S,M,A,B,R,I,N]);

var 1000..9999: NINE = 1000*N + 100*I + 10*N + E;
var 1000..9999: TIME = 1000*T + 100*I + 10*M + E;

set of int: sq4 = {n*n | n in 32..99} ;
constraint NINE in sq4;
constraint S mod 2 == 1;

%  TEST
%   MAT
%  ----
%  BEER
constraint 2 * T mod 10 == R /\ 2 * T div 10 == carry1;
constraint  (S + A + carry1) mod 10 == E /\ (S + A + carry1) div 10 == carry2;
constraint (E +  M + carry2) mod 10 == E /\  (E +  M + carry2) div 10 == carry3;
constraint  T + carry3 == B;

solve satisfy;

output [ "TIME = " ++ show(TIME) ++ ", " ++ "NINE = " ++ show(NINE)  ++ "\n" ++
"BEER = MAT + TEST" ++ "\n" ++ show(B),show(E),show(E),show(R) ++ " = " ++
show(M),show(A),show(T) ++ " + " ++ show(T),show(E),show(S),show(T) ];

% TIME = 5291, NINE = 8281
% BEER = MAT + TEST
% 6110 = 975 + 5135
% ----------
% TIME = 5291, NINE = 8281
% BEER = MAT + TEST
% 6110 = 935 + 5175
% ----------
% Finished in 137msec
```