From New Scientist #3431, 25th March 2023 [link] [link]
My burglar alarm won’t stop beeping. I need to enter the four-digit code, but I just can’t remember what it is.
I do remember that I chose a number that is divisible by 7. I also know that I chose a number in the thousands. I recall that the numbers formed by the first three digits and the last three are divisible by 7 as well. I also deliberately chose four different digits. Finally, I know that if I add all the digits, their sum isn’t divisible by 7, but if I add the digits of that sum, the result is divisible by 7.
Can you help me work out what my code is to stop the incessant beeping?
[puzzle#214]
Like this:
Like Loading...
This puzzle can be solved using the [[
SubstitutedExpression
]] solver from the enigma.py library.The following run file executes in 68ms. (Internal run time of the generated program is 329µs).
Run: [ @replit ]
Solution: The code is: 7630.
Using good ol’ Excel I can confirm that 7630 is indeed the result. After step 3 (first three and last three digits are divisible by seven), you are left with 13 pairs of numbers, all beginning with 7, which in itself is interesting – something missed, no doubt by programming fans.
I found there were 11 candidate solutions before the digit sum conditions are applied (all of the form 7xx0). None of them have a digit sum divisible by 7, so only the final condition narrows these down to a single value.
“If I add the digits of that sum” is ambiguous.
The digit sum of 7630 is 16, and if we add to it 1 + 6 we get 23,
which is not an integer multiple of 7.
The solution based on my understanding of the phrase is 7350:
digit sum 15, which when increased by 1 + 5 gives 21.
Puzzle setters should say what they mean!
I see what you mean. Fortunately each interpretation gives rise to a unique answer (although different in each case), so when the solution is published we should be able to determine what the setter had in mind.
To find the answer using this interpretation we can replace line 17 with:
It looks like the published answer is 7630 [link].
I tried this teaser on ChatGPT. It took repeated replies to correct the proposed solution where it started to go wrong. The final solution below gets the answer ABCD = 7630 which has been obtained previously as a result. (It also gets another answer i.e 2590, which is incorrect as 590 is not exactly divisible by 7.)
FINAL SOLUTION BY ChatGPT
Given:
ABCD is exactly divisible by 7.
All four digits are distinct.
The 3-digit numbers formed as ABC and BCD are also exactly divisible by 7.
The sum of the digits (A + B + C + D) is not divisible by 7.
The sum of (A + B + C + D) is a two digit number.
The sum of these two digits of the two digit number is exactly divisible by 7.
@GeoffR: You obviously had more luck (or patience) with ChatGPT than I did.
When I presented it with the problem (as originally worded) and asked it to write a Python program to solve the puzzle, then it did produce viable code.
But when I asked it what the answer to the puzzle was, it produced a set of fourteen 4-digit numbers that it claimed were solutions, but none of them were correct.
With the clarified brief at the beginning of the program,
produced a program which ran correctly, It stated on its
blog, however, that it found three answers (all of which
were incorrect) Perhaps it is the briefing line with
five asterisks which is causing the ambiguity in the original
teaser description.
The code ChatGPT produces code with very long variable
names and it was produced by ChatGPT exactly as shown
below.