Random Post
Recent Posts
Recent Comments
Archives
Categories
- article (11)
- enigma (1,609)
- enigma-book-1982 (70)
- misc (5)
- project euler (2)
- puzzle (90)
- puzzle# (173)
- site news (76)
- tantalizer (189)
- teaser (7)
- today (1)
Site Stats
- 310,317 hits
Programming Enigma Puzzles
From New Scientist #3392, 25th June 2022 [link] [link]
My son is obsessed with chess, and has been acting out the game’s moves everywhere we go, running like a bishop and jumping like a knight on tiled floors. He was tickled to see that on the number pad of my keyboard he could type 27 using a knight’s move, because the move from 2 to 7 is an L-shape, like a knight moves on a chessboard.
Alas, he can’t make 27 using a bishop move. Bishops move diagonally any number of spaces, so a bishop, using multiple moves, could make a number like 484 or 9157. In a similar fashion, a knight could make numbers such as 167 or 8349.
Yesterday, he made a happy discovery: a three-digit knight number that is exactly 27 more than a three-digit bishop number. (Actually, I found I could put another digit, call it “X”, at the front of my son’s numbers, and still have a knight number that is exactly 27 more than a bishop number).
What numbers did my son find?
[puzzle#173]
This Python program runs in 60ms. (Internal runtime is 211µs).
Run: [ @replit ]
Solution: The bishop’s number is 591, and the knight’s number is 618.
These numbers can be preceded with 1 or 7 to make 4-digit numbers with the same property.
Experimenting with operator import.
Analytical solution.
and
be the 100s, 10s and 1s digits of the knight and bishop number accordingly. Note that the digits of the bishop number must be either all odd, or all even. On the other hand, the digits of the knight number must alternate in parity, i.e. either odd/even/odd, or even/odd/even.
, so
has parity which is opposite to
. As
and
all have the same parity, and
must alternate in parity, therefore
must have the same parity as
, and
parity must be opposite to
.
and
parity is opposite to
. To avoid carry,
.
and
has the same parity as
. To have carry into the 100th digit,
. However,
is impossible, because that gives
, which is not a valid digit. So
must be 9.
Let
We know that the bishop number plus 27 equals the knight number. Let’s consider adding digits one by one.
1.
2. There should be no carry into the 10th digit, otherwise
3. There must be carry into the 100th digit, otherwise
From
, bishop can only go to 1 or 5; considering
, we get
. That gives
and
.
from either
or
. First is not valid, because it gives
, from where there is no knight move to
. So that leaves only
and
.
Bishop can get to
So the answer is 618 for the knight number and 591 for the bishop number.
Note: the information about X digit is redundant. To find X, consider that the knight can jump to 6 from either 7 or 1, and the bishop can jump to 5 from either 1, 3, 7 or 9. So
.