Le Monde puzzle [#904.5]

[This article was first published on Xi'an's Og » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

About this #904 arithmetics Le Monde mathematical puzzle:

Find all plural integers, namely positive integers such that (a) none of their digits is zero and (b) removing their leftmost digit produces a dividing integer.

a slight modification in the R code allows for a faster exploration, based on the fact that solutions add one extra digit to solutions with one less digit:

First, I found this function on Stack Overflow to turn an integer into its digits:

pluri=plura=NULL
#solutions with two digits
for (i in 11:99){

 dive=rev(digin(i)[-1])
 if (min(dive)>0){
 dive=sum(dive*10^(0:(length(dive)-1)))
 if (i==((i%/%dive)*dive))
 pluri=c(pluri,i)}}

for (n in 2:6){ #number of digits
  plura=c(plura,pluri)
  pluro=NULL
  for (j in pluri){

   for (k in (1:9)*10^n){
     x=k+j
     if (x==(x%/%j)*j)
       pluro=c(pluro,x)}
   }
   pluri=pluro}

which leads to the same output

> sort(plura)
 [1] 11 12 15 21 22 24 25 31 32 33 35 36
[13] 41 42 44 45 48 51 52 55 61 62 63 64
[25] 65 66 71 72 75 77 81 82 84 85 88 91
[37] 92 93 95 96 99 125 225 312 315 325 375 425
[49] 525 612 615 624 625 675 725 735 825 832 912 
[61] 915 925 936 945 975 1125 2125 3125 3375 4125 
[70] 5125 5625 
[72] 6125 6375 7125 8125 9125 9225 9375 53125 
[80] 91125 95625

Filed under: Books, Kids, R, Statistics, University life Tagged: arithmetics, Le Monde, mathematical puzzle, strsplit()

To leave a comment for the author, please follow the link and comment on their blog: Xi'an's Og » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)