[This article was first published on R – Xi'an's Og, 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.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
- Bob gets a 2×3 card with three integer entries on the first row and two integer entries on the second row such that (i) entry (1,1) is 1, (ii) summing up subsets of adjacent entries produces all integers from 1 to 21. (Adjacent means sharing an index.) Deduce Bob’s voucher.
- Alice gets Bob’s voucher completed into a 2×4 card with further integer entries. What is the largest value of N such that all integers from 1 to N are available through summing up all subsets of entries?
The first question only requires a few attempts but it can be solves by brute force simulation. Here is a R code that leads to the solution:
alsumz<-function(sol){return( c(sol,sum(sol[1:2]),sum(sol[2:3]),sum(sol[4:5]), sum(sol[c(1,4)]), sum(sol[c(1,5)]),sum(sol[1:3]), sum(sol[c(1,4,5)]),sum(sol[c(1,2,5)]), sum(sol[c(2,4,5)]), sum(sol[c(1,2,3,5)]),sum(sol[2:5]), sum(sol[c(1,2,4)]),sum(sol[c(1,2,4,5)]),sum(sol[1:4]), sum(sol)),sum(sol[c(2,3,5)]))}
produces (1,8,7,3,2) as the only case for which
(length(unique(alsum(sol)))==21)
The second puzzle means considering all sums and checking there exists a solution for all subsets. There is no constraint in this second question, hence on principle this could produce N=2⁸-1=255, but I have been unable to exceed 175 through brute force simulation. (Which entitled me to use the as.logical(intToBits(i) R command!)
Filed under: Books, Kids, R Tagged: Alice and Bob, Le Monde, mathematical puzzle, partition, R
To leave a comment for the author, please follow the link and comment on their blog: R – Xi'an's Og.
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.