Le Monde puzzle 847 in Julia

[This article was first published on Wiekvoet, 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.

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 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.

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)