Le Monde puzzle [#825]

[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.

The current puzzle is the last one before the summer break and not exciting enough to take along:

Take the first ten digits, create five pairs out of those, and for each pair (x,y) derive the quantity (min(x,y)+1.5max(x,y)). What is the collection of pairs that maximises the product of those quantities?

I wrote the following R code in the train back from Annecy:

res=0
bonus=1.5
for (t in 1:1000){
x=matrix(sample(1:10),ncol=2)
mix=apply(x,1,min);mox=apply(x,1,max)
rex=prod(mix+bonus*mox)
if (rex>res){
  print(x)
  res=rex}
}

and got:

     [,1] [,2]
[1,]    9    1
[2,]    4    7
[3,]    2   10
[4,]    8    3
[5,]    5    6

Thus the sum of the pairs is always equal to 11. And by changing bonus you can check this is true for all values of the coefficient that are larger than one (one included).


Filed under: Books, Kids, R Tagged: factors(), Le Monde, mathematical puzzle, R, summer, vacations

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)