### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,115)
- misc (2)
- project euler (2)
- puzzle (29)
- site news (43)
- tantalizer (29)
- teaser (3)

### Site Stats

- 166,357 hits

Programming Enigma Puzzles

11 November 2012

Posted by on **From New Scientist #2644, 23rd February 2008**

My nephew was playing with some counters, so I decided to give him a mathematical exercise using them. I asked him to calculate how many ways there were of dividing his counters into three piles. For example, eight counters could be divided into three piles five ways, namely 1+1+6, 1+2+5, 1+3+4, 2+2+4 and 2+3+3.

After some time he wrote down his four-digit answer but I assumed that he had made a slight error in writing it down because I knew the correct answer and saw that in his number the middle two digits had been swapped over.

However, it turned out that he had made his error when counting, not when writing the number down. He had assumed that the three piles had to contain different numbers of counters, and had done his calculations accordingly. (So for example, with eight counters he would have got the answer “two” rather than “five””.)

How many counters did he have?

This puzzle marks the start of my attempts at programmatic solutions to *Enigma* puzzles as they are published. Before this I only attempted them sporadically, when a puzzle caught my fancy. Eventually I decided to collect my solutions and put them up on this site.

[enigma1482]

Advertisements

%d bloggers like this:

The following Python program runs in 93ms.

Solution:There are 182 counters.It took me a while to find the formula, but only because I was tackling things the hard way.

The number of ways of dividing n counters into three piles is int(n²/12 + ¼).

In fact the “plus a quarter” is needed only when n is an odd multiple of 3.

With three different piles, it’s the same formula with n – 3 in place of n.

So for n = 182 we get 2760 and 2670.