Le Monde puzzle [#854]
A Le Monde mathematical puzzle that sounds similar to earlier ones:
Find all integers x between 1000 and 9999 and N≥1 such Nx has the reverse sequence of digits compared with i.
For N=1, the appropriate integers x are such that the four digits are symmetrical, as in x=3553. For N≥1, I ran the following R code:
for (i in 10^3:(5*10^3)){ dig=rev(intToDigits(i)) for (N in 2:8){ if (N*i>9999) break() if (max(abs(intToDigits(N*i)-dig))<.1) print(c(i,N,N*i)) }}
and only found the single entry
[1] 2178 4 8712
where the intToDigits function was suggested to me by Pierre Pudlo:
intToDigits <- function(x) { if (length(x) != 1) { warning( "x should be of length 1. Using only x[1]") x <- x[1] } m <- floor(log10(x)) + 1 pow10 <- 10^(1:m) xpow <- x * pow10 / (10^m) xrep <- trunc(xpow) / pow10 digits <- c(xrep[1], xrep[-1]-xrep[-m]) * pow10 digits }
February 22, 2014 at 3:38 pm
Thanks so much Christian for this weekly challenge of the Monde puzzle that I have not worked out for a while.
Here is an attempt to solve this one without a computer.
Letting X=(abcd) in decimal notations so that its symmetric Y=(dcba)
Let us restrict to the case of no carry over for getting d so that d=Na with N>1
Then a(N^2)=a modulo 10 with the only acceptable solution N=4 and a=2 on account of the constraints (in particular N=4, a=4 excluded)
No we have to solve 4x(2bc8)=(8cb2) ie 4c+3=b modulo 10 and 4b+[(4c+3)/10]=c
Leading to c=7 and b=1 so that X=2178 and Y=8712
February 21, 2014 at 8:45 pm
How about this (without bells, etc.) for intToDigits:
f unction (x)
{
as.numeric(unlist(strsplit(as.character(x),”)))
}