## Le Monde puzzle [#902]

**A**nother arithmetics Le Monde mathematical puzzle:

From the set of the integers between 1 and 15, is it possible to partition it in such a way that the product of the terms in the first set is equal to the sum of the members of the second set?can this be generalised to an arbitrary set {1,2,..,n}?What happens if instead we only consider the odd integers in those sets?.

I used brute force by looking at random for a solution,

pb <- txtProgressBar(min = 0, max = 100, style = 3) for (N in 5:100){ sol=FALSE while (!sol){ k=sample(1:N,1,prob=(1:N)*(N-(1:N))) pro=sample(1:N,k) sol=(prod(pro)==sum((1:N)[-pro])) } setTxtProgressBar(pb, N)} close(pb)

and while it took a while to run the R code, it eventually got out of the loop, meaning there was at least one solution for all n’s between 5 and 100. (It does not work for n=1,2,3,4, for obvious reasons.) For instance, when n=15, the integers in the product part are either 3,5,7, 1,7,14, or 1,9,11. Jean-Louis Fouley sent me an explanation: when n is odd, n=2p+1, one solution is (1,p,2p), while when n is even, n=2p, one solution is (1,p-1,2p).

A side remark on the R code: thanks to a Cross Validated question by Paulo Marques, on which I thought I had commented on this blog, I learned about the progress bar function in R, *setTxtProgressBar()*, which makes running R code with loops much nicer!

For the second question, I just adapted the R code to exclude even integers:

while (!sol){ k=1+trunc(sample(1:N,1)/2) pro=sample(seq(1,N,by=2),k) cum=(1:N)[-pro] sol=(prod(pro)==sum(cum[cum%%2==1])) }

and found a solution for n=15, namely 1,3,15 versus 5,7,9,11,13. However, there does not seem to be a solution for all n’s: I found solutions for n=15,21,23,31,39,41,47,49,55,59,63,71,75,79,87,95…

*Related*

This entry was posted on March 8, 2015 at 12:15 am and is filed under Books, Kids, Statistics, University life with tags Chib's approximation, Le Monde, mathematical puzzle, mixture estimation, progress bar, R, txtProgressBar. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

March 8, 2015 at 8:14 pm

seems likes a solution when n is prime or n = \prod p_i where

p_i are all distinct primes?

March 8, 2015 at 1:13 am

setTxtProgressBar() is an excellent function! Thanks! So much better than my usual “let’s spit out integers” technique.

March 8, 2015 at 5:03 pm

Yes, as soon as I saw it, I adopted it! Note however that the counter is for the loop index and not for time!

March 10, 2015 at 6:29 pm

When I was a PhD student there were two sorts of programs in the lab. Those that counted, and those that printed dots on the screen…

March 10, 2015 at 8:54 pm

================================ 200%