Teaser 2645: One square
From The Sunday Times, 2nd June 2013 [link] [link]
I have consistently replaced digits by letters, using different letters for different digits, and in this way I have found that:
(FIVE − FOUR)² = ONE
Now, if I were to tell you whether or not THREE is divisible by 3, and whether or not FOUR is divisible by 4, then you could work out FIVE.
What number is FIVE?
Note: As originally published this puzzle has no solution (and was reproduced in this flawed form in the book The Sunday Times Brain Teasers Book 2 (2020)).
However the additional information that “FIVE is greater than FOUR” allows the published answer to be found.
[teaser2645]
Jim Randell 9:29 am on 7 September 2023 Permalink |
With the extra condition that “FIVE is greater than FOUR” we find the published answer.
So maybe the setter intended to say: “… I have found that FIVE − FOUR is a positive number, whose square is ONE” (or: “the square root of ONE is equal to FIVE – FOUR“).
This Python program runs in 147ms.
Run: [ @replit ]
from enigma import (SubstitutedExpression, group, unpack, item, peek, seq2str, printf) # the alphametic problem (with an additional condition) p = SubstitutedExpression( ["sq(FIVE - FOUR) = ONE", "FIVE > FOUR"], answer="(THREE, FOUR, FIVE)", ) # collect the answers, and record values of FIVE (= item(2)) # by (THREE divisible by 3, FOUR divisible by 4). fn = unpack(lambda n3, n4, n5: (int(n3 % 3 == 0), int(n4 % 4 == 0))) d = group(p.answers(verbose=0), by=fn, f=item(2), fn=set) # output the collections, and find the solution for (k, vs) in d.items(): if len(vs) == 1: printf("(d3, d4) = {k} -> FIVE = {v} [*** SOLUTION ***]", v=peek(vs)) else: printf("(d3, d4) = {k} -> FIVE = {vs}", vs=seq2str(vs, sort=1, enc="{}"))Solution: FIVE = 5901.
If we are told THREE is not divisible by 3, and FOUR is divisible by 4, then the only possible assignments are:
Any of the other of the divisibility possibilities lead to multiple candidate values for FIVE, so this gives the answer.
However if we do not require FIVE > FOUR, then we find many further possible solutions to the alphametic problem:
And so we cannot work out the value of FIVE.
We can see these candidates by removing the [[
"FIVE > FOUR"]] on line 5 of the program.LikeLike
Frits 12:32 pm on 8 September 2023 Permalink |
The reported run time 147ms was probably with PyPy (I get 423ms with CPython).
With this program CPython performs better than PyPY.
from enigma import (SubstitutedExpression, group, unpack, item, peek, seq2str, printf) # invalid digit / symbol assignments d2i = dict() for d in range(0, 10): vs = set() if d == 0: vs.update('OFT') # if E is odd then R is even and if E is even then R is even as well if d % 2: vs.update('R') # a number that ends in 2, 3, 7 or 8 is not a perfect square if d in {2, 3, 7, 8}: vs.update('E') d2i[d] = vs # the alphametic problem (with an additional condition) p = SubstitutedExpression( [ # FIVE > FOUR "I > O", "sq(IVE - OUR) = ONE",], answer="(FOUR, FIVE, THREE)", #answer="(FOUR, FIVE, \ # R + 2*E + sum(i for i in range(10) if i not in {F,I,V,E,O,U,R,N}))", d2i=d2i, verbose=0 ) # collect the answers, and record values of FIVE (= item(1)) # by (THREE divisible by 3, FOUR divisible by 4). fn = unpack(lambda n4, n5, n3: (int(n3 % 3 == 0), int(n4 % 4 == 0))) d = group(p.answers(), by=fn, f=item(1), fn=set) # output the collections, and find the solution for (k, vs) in d.items(): if len(vs) == 1: printf("(d3, d4) = {k} -> FIVE = {v} [*** SOLUTION ***]", v=peek(vs)) else: printf("(d3, d4) = {k} -> FIVE = {vs}", vs=seq2str(vs, sort=1, enc="{}"))LikeLike
Jim Randell 12:13 pm on 9 September 2023 Permalink |
@Frits: Yes, 147ms was with PyPy 7.3.12. With CPython 3.12 I get an overall runtime of 255ms.
Although, if you are solving the rescued problem you can use the expression [[
"is_square(ONE) + FOUR = FIVE"]] which is a bit faster, and it is even faster to use [["is_square(ONE) + OUR = IVE"]] (93ms with CPython 3.12).LikeLike