Enigmatic Code

Programming Enigma Puzzles

Puzzle #212: Sound off

“Why isn’t the sound working?”, Mum muttered as she hit the mute key on the remote control.

“You’ve probably got the wrong remote, Mum”, Sam said. “Remember, it’s the long, thin one for the television, the wide one for the set-top box and the little one for the speakers. Which one did you mute?”

“I can’t remember”, said Mum, as she got her thinking cap on to try to fix things.

To get sound, all three remotes have to be unmuted. Mum came up with the most efficient system for cycling through the possible combinations of muting and unmuting, and got to work.

What is the maximum number of presses needed if she wanted to be sure of getting the sound back?

[puzzle#212]

3 responses to “Puzzle #212: Sound off”

1. Jim Randell 10 March 2023 at 5:28 pm

If just one of the devices is muted we can pick any remote and press mute/unmute.

If this gives sound were are done, otherwise we press mute/unmute again, to go back to the original state.

We then pick one of the remaining remotes, and press mute/unmute.

If this gives sound were are done, otherwise we press mute/unmute again, to go back to the original state.

We then take the final remote and press mute/unmute.

If this doesn’t give sound then the problem wasn’t that exactly one of the devices was muted.

So this solves the problem in 1, 3, or 5 button presses, and this is minimal.

This Python program shows that we cannot have a sequence of moves that is guaranteed to solve the problem in fewer than 5 presses.

```from enigma import (irange, inf, subsets, update, printf)

# using presses <ps> how many moves get us from <src> to <tgt>
def solve(ps, src, tgt):
for (n, p) in enumerate(ps, start=1):
src = update(src, [(p, src[p] ^ 1)])
if src == tgt: return n
return None

# possible sources (any one of the devices may be muted)
srcs = [(0, 1, 1), (1, 0, 1), (1, 1, 0)]
# target state (all devices have sound)
tgt = (1, 1, 1)

# choose a set of presses
for ps in subsets((0, 1, 2), min_size=1, max_size=inf, select="M"):
# find distances for each possible source
ns = list(solve(ps, src, tgt) for src in srcs)
if None in ns: continue
printf("{ps} -> {ns}")
break  # we only need the first solution
```
• Jim Randell 17 March 2023 at 9:48 am

Apparently the setter intended the three devices may be in any mute state (apart from all unmuted).

We can adapt the program to solve this scenario by changing line 11:

```# possible sources (some of the devices are muted)
srcs = [(0, 0, 0), (0, 0, 1), (0, 1, 0), (1, 0, 0), (0, 1, 1), (1, 0, 1), (1, 1, 0)]
```

We then find a minimal sequence of length 7 that will resolve these situations in 1-7 presses:

```% python3 puzzle-212.py
(0, 1, 0, 2, 0, 1, 0) -> [5, 2, 6, 4, 1, 3, 7]
```
2. ilya 20 April 2023 at 4:14 am