Teaser 2888: Two sums
From The Sunday Times, 28th January 2018 [link] [link]
Digits have been systematically replaced by letters to give:
ONE + ONE = TWO
ONE + FOUR = FIVENo number consists of a consecutive set of digits.
What number is represented by FIFTEEN?
[teaser2888]
Jim Randell 10:10 am on 9 August 2019 Permalink |
We can easily use the [[
SubstitutedExpression()]] solver from the enigma.py library to solve the alphametic sums, and we can use [[--code]] parameters to provide the additional check that none of the numbers consist of a set of consecutive digits. The numbers are all composed of different digits, so that makes things a bit simpler.This run file executes in 139ms.
Run: [ @repl.it ]
Solution: FIFTEEN = 9594663.
We have:
There is one other solution to the alphametic sums that is eliminated because FOUR is composed from a set of (numerically) consecutive digits:
So we could just generate both solutions to the alphametic sums, and remove the non-viable solution by inspection.
LikeLike
GeoffR 3:05 pm on 11 August 2019 Permalink |
% A Solution in MiniZinc include "globals.mzn"; var 1..9: O; var 0..9: N; var 1..9: F; var 0..9: R; var 0..9: E; var 1..9: T; var 0..9: W; var 0..9: I; var 0..9: V; var 0..9: U; constraint all_different([U, O, N, E, F, R, T, W, I, V]); % check ONE for non-consecutive digits var set of int : s1 = {O,N,E}; constraint max ([O,N,E]) - min([O,N,E]) != card(s1) - 1; var 100..999: ONE = 100*O + 10*N + E; % check TWO for non-consecutive digits var set of int : s2 = {T,W,O}; constraint max ([T,W,O]) - min([T,W,O]) != card(s2) - 1; var 100..999: TWO = 100*T + 10*W + O; % check FOUR for non-consecutive digits var set of int : s3 = {F,O,U,R}; constraint max ([F,O,U,R]) - min([F,O,U,R]) != card(s3) - 1; var 1000..9999: FOUR = 1000*F + 100*O + 10*U + R; % check FIVE for non-consecutive digits var set of int : s4 = {F,I,V,E}; constraint max ([F,I,V,E]) - min([F,I,V,E]) != card(s4) - 1; var 1000..9999: FIVE = 1000*F + 100*I + 10*V + E; constraint ONE + ONE == TWO; constraint ONE + FOUR == FIVE; solve satisfy; output [ "ONE = " ++ show(ONE) ] ++ [ ", TWO = " ++ show(TWO) ] ++ [ ", FOUR = " ++ show(FOUR) ] ++ [ ", FIVE = " ++ show(FIVE) ] ++ [ "\nFIFTEEEN = " ++ show(F),show(I),show(F),show(T),show(E),show(E),show(N)]; % ONE = 236, TWO = 472, FOUR = 9280, FIVE = 9516 % FIFTEEEN = 9594663 % time elapsed: 0.02 s % ---------- % ========== % Finished in 231msecLikeLike