Le Monde puzzle 847 in Julia

January 4, 2014

(This article was first published on Wiekvoet, and kindly contributed to R-bloggers)

This week I wanted to play around with Julia and exporting the results. I found http://xianblog.wordpress.com/2013/12/29/le-monde-puzzle-847/ to be just the right size to play around with.


A function to check if a triplet has the desired property
In [1]:

function lemonde847(xx)


lemonde847 (generic function with 1 method)

Just a check – the function does indeed result in 1768 for the triplet 6 5 13.
In [2]:




Check all combinations of numbers 1 to 60 excluding 2, 4 and 8. These need to be permuted later on. 60 may be a bit much, but how to calculate a bound? After all, imagine a set 1 3 60, that is only 1428. On the other hand, a combination with 59 and 60 should be too large. Hence we make a filter to exclude some. The rows where all three test numbers multiplied are higher than 1768. The remaining combinations are permuted and tested.
In [3]:




In [4]:

totest = collect(combinations( symdiff(1:50, [2,4,8]),3))


16215-element Array{Array{Int64,1},1}:


In [5]:

for i in 1:size(totest)[1] 
if prod(totest[i,])<1768
test2 = collect(permutations(totest[i,]))
for j in 1:6
if lemonde847(test2[j,])==1768
6 5 13

Seems I found the answer; 6 5 13. The only thing left is to export the results. A bit of googling showed http://ipython.org/ipython-doc/stable/interactive/nbconvert.html.

Final Notes


In the end I converted the script via:
ipython nbconvert  lemonde847.ipynb
The resulting file was opened in libreoffice and copied pasted into blogger. This gave a bit better results than conversion using
ipython nbconvert –template basic lemonde847.ipynb
and a copy paste of the .html directly in blogger.
Some post editing was done after examination of the preview of the post, but that is fairly normal for me. 

Time usage

The calculation time was minimal. Most of the time was used in understanding Julia syntax, debugging, writing code, writing blog text, installation of pandoc. A lot of these things are one-off, but still, this last sentence took more time than the computation time.

To leave a comment for the author, please follow the link and comment on their blog: Wiekvoet.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


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)