% A Solution in MiniZinc
% S E V E N
% T H R E E
% T W O
% -----------
% T W E L V E
% -----------
include "globals.mzn";
var 1..9:S; var 0..9:E; var 0..9:V; var 0..9:N;
var 1..9:T; var 0..9:H; var 0..9:R; var 0..9:W;
var 0..9:O; var 0..9:L;
% Carry digits for adding columns
var 0..2: carry1; var 0..2: carry2; var 0..2: carry3;
var 0..2: carry4; var 0..2: carry5;
constraint all_different([S, E, V, N, T, H, R, W, O, L]);
% Working left from the right hand column
constraint (N + E + O) mod 10 == E
/\ (N + E + O) div 10 == carry1;
constraint (2*E + W + carry1) mod 10 == V
/\ (2*E + W + carry1) div 10 == carry2;
constraint (V + R + T + carry2) mod 10 == L
/\ (V + R + T + carry2) div 10 == carry3;
constraint (E + H + carry3) mod 10 == E
/\ (E + H + carry3) div 10 == carry4;
constraint (S + T + carry4) mod 10 == W
/\ (S + T + carry4) div 10 == carry5;
constraint T = carry5;
solve satisfy;
output [ "LETTERS = " ++ show(L),show(E),
show(T),show(T),show(E), show(R),show(S) ]
++ ["\n" ++ "SEVEN = " ++ show(S),show(E),
show(V),show(E),show(N)]
++ [", THREE = " ++ show(T),show(H),show(R),
show(E),show(E) ]
++ [", TWO = " ++ show(T),show(W),show(O) ]
++ [", TWELVE = " ++ show(T),show(W),show(E),
show(L),show(V),show(E)];
% LETTERS = 3211278
% SEVEN = 82526, THREE = 19722, TWO = 104, TWELVE = 102352
% -----------------
% LETTERS = 3211278
% SEVEN = 82524, THREE = 19722, TWO = 106, TWELVE = 102352
% Finished in 161msec
Jim Randell 10:39 am on 11 October 2019 Permalink |
This is a straightforward alphametic sum.
We can solve it using the [[
SubstitutedSum()
]] solver from the enigma.py library.The following command executes in 164ms.
Run: [ @repl.it ]
Solution: LETTERS = 3211278.
The values for N and O can be interchanged, but we are asked for the value of LETTERS, so the solution is unique.
LikeLike
GeoffR 11:01 am on 12 October 2019 Permalink |
LikeLike