### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,383)
- misc (4)
- project euler (2)
- puzzle (90)
- puzzle# (56)
- site news (61)
- tantalizer (101)
- teaser (7)
- today (1)

### Site Stats

- 240,810 hits

Programming Enigma Puzzles

21 March 2020

Posted by on **From New Scientist #3274, 21st March 2020** [link] [link]

It is Tom’s 7th birthday and he has a cake with seven candles on it, arranged in a circle – but they are trick candles. If you blow on a lit candle, it will go out, but if you blow on an unlit candle, it will relight itself.

Since Tom is only 7, his aim isn’t brilliant. Any time he blows on a particular candle, the two either side also get blown on as well.

How can Tom blow out all the candles? What is the fewest number of puffs he can do it in?

[puzzle#51]

%d bloggers like this:

Note:I solved a slightly different problem – where you can only aim for a candle that is lit.This Python program runs in 155ms.

Run:[ @repl.it ]Solution:Tom can blow out the candles with 9 puffs.Here is a diagram:

We start with all the candles alight (indicated by 1) and then in each row the state of the highlighted candles is flipped, until after 9 operations all the candles are out (indicate by 0).

There is another way. If Tom blows once on each of his seven candles in any order, that makes them all go out.

@Julian: I see. I was only allowing blowing on candles that were lit. It seems that I was assuming a behaviour of 7 year old boys that isn’t specified in the puzzle text.

I expect your interpretation is the correct one.

Here is my program modified to allow aiming at any candle (lit or unlit).

It confirms that the candles can be blown out with only 7 puffs.

Aiming for each candle (in any order) means that each candle’s state will be flipped 3 times (once as the intended target, once as the intended target + 1, and once as the intended target – 1), so they will all end up extinguished. This works for any number of candles, but isn’t always the minimum number (e.g. when the number of candles is a multiple of 3, they can just be blown out in groups of 3).