Teaser 2495: [Alphametic]
From The Sunday Times, 18th July 2010 [link] [link]
I have taken some numbers and consistently replaced the digits by letters, with different letters for different digits, in this way:
FOUR is a perfect square;
EIGHT is a perfect cube;
ONE + TEN is a prime.What is the value of THREE?
This puzzle was originally published with no title.
[teaser2495]
Jim Randell 8:14 am on 24 October 2025 Permalink |
Here is a solution using the [[
SubstitutedExpression]] solver from the enigma.py library, that is a direct interpretation of the puzzle statement.The following run file executes in 227ms. (Internal runtime of the generated code is 59ms).
Solution: THREE = 42911.
We have:
LikeLike
Ruud 7:48 am on 25 October 2025 Permalink |
import peek import istr for x2 in istr.range(32, 100): for x3 in istr.range(22, 47): for n in istr.range(10): f, o, u, r = [*x2**2] e, i, g, h, t = [*x3**3] if ((o | n | e) + (t | e | n)).is_prime() and ((f | o | u | r | e | i | g | h | t | n).all_distinct()): peek(t | h | r | e | e)LikeLike
GeoffR 8:58 pm on 25 October 2025 Permalink |
% A Solution in MiniZinc include "globals.mzn"; var 0..9: U; var 0..9: I; var 0..9: R; var 0..9: G; var 0..9: H; var 0..9: N; var 1..9: O; var 1..9: F; var 1..9: E; var 1..9: T; constraint all_different([U,I,R,G,H,N,O,F,E,T]); var 100..999:ONE == 100*O +10*N + E; var 100..999:TEN == 100*T +10*E + N; var 1000..9999: FOUR == 1000*F + 100*O + 10*U + R; var 10000..99999: EIGHT == 10000*E + 1000*I + 100*G + 10*H + T; var 10000..99999: THREE == 10000*T + 1000*H + 100*R + 11*E; set of int: sq4 = {n*n | n in 32..99}; set of int: cb5 = {n*n*n | n in 22..46}; predicate is_prime(var int: x) = x > 1 /\ forall(i in 2..1 + ceil(sqrt(int2float(ub(x))))) ((i < x) -> (x mod i > 0)); constraint FOUR in sq4 /\ EIGHT in cb5 /\ is_prime(ONE + TEN); solve satisfy; output ["THREE = " ++ show(THREE) ++ "\n" ++ "FOUR = " ++ show(FOUR) ++ "\n" ++ "EIGHT = " ++ show(EIGHT) ++ "\n" ++ "ONE = " ++ show(ONE) ++ "\n" ++ "TEN = " ++ show(TEN)]; % THREE = 42911 % FOUR = 7569 % EIGHT = 13824 % ONE = 501 % TEN = 410 % ---------- % ==========LikeLike
ruudvanderham 3:04 pm on 26 October 2025 Permalink |
With the latest version of istr, we can decompose and compose to/from one letter variables, resulting in cleaner code:
import istr import peek for x2 in istr.range(32, 100): for x3 in istr.range(22, 47): for n in istr.range(10): (x2**2).decompose("four") (x3**3).decompose("eight") if (istr.compose("one") + istr.compose("ten")).is_prime() and istr.compose("foureightn").all_distinct(): peek(istr.compose("three"))LikeLike