Yesterday, while reading the last issue of the NewScientist, I came across the following very cute riddle:

Lazy, I asked myself if it were possible to write lines long Python code to solve this innocent looking enigma. The whole pyramid is entirely determined by the numbers lying at the bottom, and each one of them is an integer between and : these numbers must be different so that there are at most possibilities to test! Brute force won’t work my friend!

When stupid brute force does not work, one can still try annealing/probabilist methods: this works pretty well for Sudoku (which is NP-hard) as this is brilliantly described here and there. The principle is simple: if one can find a good energy function such that a solution to the problem corresponds to a low energy configuration, one can do MCMC-simulating annealing-etc on the target distribution

The issue is that it might be very difficult to choose a sensible energy function . Foolishly, I first tried the following energy function, and then ran a random walk Metropolis algorithm with as target probability:

where is the numbers of levels that one can fill, starting from the bottom, without encountering any problem no repetition and no number greater than . With different values of and letting run the algorithm for a few millions iterations ( min on my crappy laptop), one can easily produce configurations that are -levels high: but the algorithm never found any real solution a configuration with height equal to .

Now I am curious wether this is possible to produce a non-stupid energy function so that this riddle is solvable in a reasonable amount of time by standard MCMC – annealing methods.

As a conclusion, I should mention that with a pen and a cup of coffee, one can easily find a solution: I will not spoil the fun, but just say that the configuration space is not that big if one think more carefully about it…

### Like this:

Like Loading...

*Related*

## Basil said,

February 14, 2011 at 6:32 pm

Interesting method. I think I’ll try this one at lunch.