### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,149)
- misc (2)
- project euler (2)
- puzzle (38)
- site news (44)
- tantalizer (40)
- teaser (3)

### Site Stats

- 175,242 hits

Advertisements

Programming Enigma Puzzles

25 July 2012

Posted by on **From New Scientist #2686, 13th December 2008** [link]

Some three-digit primes are formed from a one-digit prime followed by a two-digit prime, others from a two-digit prime followed by a one-digit prime, and some can be in both classes.

I recently bought three pieces of furniture, and each cost a different sum which was one of the last-mentioned type of prime (in euros), but the total I paid was not a prime.

In ascending order, what were the prices of my pieces of furniture?

[enigma1524]

Advertisements

%d bloggers like this:

Here’s my original Perl solution. It’s one of the rare cases where I use

Math::Combinatorics, rather than separateforloops. It runs in 34ms.Solution:The prices were €313, €317 and €373.Here’s a Python solution. It uses a prime sieve to select the initial primes. It runs in 43ms.

Am I missing something here? If the last digits of the three primes are respectively 1, 1, 3, or 3, 3, 9, or 7, 7, 1, or 9, 9, 7, then the total ends in 5 so is not a prime.

I found fourteen primes that fall into the required class, so there are numerous possibilities.

Don’t we need a further condition or restriction?

Oops! I overlooked the fact that 1 and 9 are not prime. Sorry about that. Need a stronger coffee.