[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.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Since I have resumed my R class, I will restart my resolution of Le Monde mathematical puzzles…as they make good exercises for the class. The puzzle this week is not that exciting:
Find the four non-zero different digits a,b,c,d such that abcd is equal to the sum of all two digit numbers made by picking without replacement two digits from {a,b,c,d}.
The (my) dumb solution is to proceed by enumeration
for (a in 1:9){ for (b in (1:9)[-a]){ for (c in (1:9)[-c(a,b)]){ for (d in (1:9)[-c(a,b,c)]){ if (231*sum(c(a,b,c,d))==sum(10^(0:3)*c(a,b,c,d))) print(c(a,b,c,d)) }}}}
taking advantage of the fact that the sum of all two-digit numbers is (30+4-1) times the sum a+b+c+d, but there is certainly a cleverer way to solve the puzzle (even though past experience has shown that this was not always the case!)
Filed under: R, University life Tagged: class, Le Monde, mathematical puzzle, R
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.