Although the alphametic
SEVEN+EIGHT=TWELVE conveys a false message, it has several (how many?) valid solutions.
Find the one with the largest W.
In a total of 6 solutions, the largest W (= 5) is in
69298 + 90431 = 159729,
that is next to the last one:
---------
Solutions
---------
| ?- jm([S,E,V,N,I,G,H,T,W,L],[]).
SEVEN 36465
+ EIGHT 69781
= TWELVE 106246
E = 6,
G = 7,
H = 8,
I = 9,
L = 2,
N = 5,
S = 3,
T = 1,
V = 4,
W = 0 ? ;
SEVEN 38487
+ EIGHT 89561
= TWELVE 128048
E = 8,
G = 5,
H = 6,
I = 9,
L = 0,
N = 7,
S = 3,
T = 1,
V = 4,
W = 2 ? ;
SEVEN 58287
+ EIGHT 80641
= TWELVE 138928
E = 8,
G = 6,
H = 4,
I = 0,
L = 9,
N = 7,
S = 5,
T = 1,
V = 2,
W = 3 ? ;
SEVEN 63732
+ EIGHT 39841
= TWELVE 103573
E = 3,
G = 8,
H = 4,
I = 9,
L = 5,
N = 2,
S = 6,
T = 1,
V = 7,
W = 0 ? ;
SEVEN 69298
+ EIGHT 90431
= TWELVE 159729
E = 9,
G = 4,
H = 3,
I = 0,
L = 7,
N = 8,
S = 6,
T = 1,
V = 2,
W = 5 ? ;
SEVEN 85254
+ EIGHT 50671
= TWELVE 135925
E = 5,
G = 6,
H = 7,
I = 0,
L = 9,
N = 4,
S = 8,
T = 1,
V = 2,
W = 3
-------
Program
-------
jm([S,E,V,N,I,G,H,T,W,L],Type) :-
domain([S,E,V,N,I,G,H,T,W,L],0,9),
S#>0,E#>0,T#>0,
all_different([S,E,V,N,I,G,H,T,W,L]),
sum(S,E,V,N,I,G,H,T,W,L),
labeling(Type,[S,E,V,N,I,G,H,T,W,L]).
sum(S,E,V,N,I,G,H,T,W,L) :-
10000*S + 1000*E + 100*V + 10*E + N
+ 10000*E + 1000*I + 100*G + 10*H + T
#= 100000*T + 10000*W + 1000*E + 100*L + 10*V + E.
|
Posted by ollie
on 2016-12-02 16:22:04 |