Pep, thanks – I had forgotten the 1/N^3 part which is why the 3/2*alpha seemed strange, being > 1 .

]]>Hi Carl,

I checked again my demonstration of the analytic formula and seems ok to me. Of course, I’m assuming a particular reading of the expression. Do you suggest I could write it this way:

(3/2) * n^2 – 2 * n + (3/2) * alpha;

where alpha = 0 if n is even, alpha = 1 if n is odd?

I could also include the factor 1/n^3 multiplying the whole expression above to give the expression for the probability, that is what the challenge ask for.

Thanks a lot for your comment.

Have a wonderful day,

Pep

Pep, you seem to be missing some parentheses in your analytic formula. Can you check & re-post?

thank you

Thanks, I was not aiming at speed but shortness of code, which is the essence of codegolf, and admittedly quite silly!!!

]]>Thanks a lot for writing this post.

The solution to the problem reads:

3/2*n^2-2*n+3/2*alpha

where alpha = 1 if n is odd and alpha = 0 if n is even.

Another brute force solution, enumerating all possible 3 number trios, reads:

sum(

apply(

expand.grid(1:n, 1:n, 1:n), 1, function(x) {

m <- mean(x)

return(m == x[1] || m == x[2] || m == x[3])

#!(mean(x) – median(x))

}

)

)

Using your smart check "mean – median" seems to take longer to compute it than the direct condition check (m==x[1] …).

It would be nice to include a photo of the board of the coffee room with the challenge stated.

Have a wonderful day,

Pep

Thank you Carl, this is correct. I only ran the reasoning with N even.

]]>Thanks, I had lost the matrix in the cut&paste! And replicate is indeed a better choice (60 vs. 75 characters). But there should be a ! in front.

]]>