# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1305: Buzz

From New Scientist #2463, 4th September 2004

In the game of buzz the players form a circle and count in turn, the first saying “1”, the next “2”, the next “3” and so on. But every time the next number is a multiple of 7 or contains a 7 the player whose turn it is must say “buzz”, and then the direction in which play is going round the circle is reversed; so after the sixth player says “6”, the seventh says “buzz”, then the one who said 6 says “8” and the one who said 5 says “9” and so on until a player says “buzz” rather than 14, whereupon the one who said 13 must say “15”.

At 27 and 28, and again at 56 and 57, the direction of play is reversed twice in succession, and through the 70s two players must each say “buzz” five times alternately.

In a game which only ended when a player said “97” instead of “buzz” my only contribution was to say “buzz” twice.

(a) Which two numbers did I say “buzz” for?

(b) How many players took part?

[enigma1305]

### 2 responses to “Enigma 1305: Buzz”

1. Jim Randell 31 July 2014 at 7:56 am

This Python program records the utterances of the player in n-player games (a buzz is recorded as a negative number). It runs in 32ms.

```from collections import defaultdict
from itertools import count
from enigma import printf

def play(n):
# record the utterances for each player
r = defaultdict(list)
# player, number, direction
(p, i, d) = (1, 1, 1)
while i < 97:
s = str(i)
buzz = (i % 7 == 0 or '7' in s)
r[p].append(-i if buzz else i)
if buzz:
d = -d
i += 1
p += d
if p > n: p -= n
if p < 1: p += n
return r

for n in count(2):
r = play(n)
# look for players who only say "buzz" twice
ps = list((k, v) for (k, v) in r.items() if len(v) == 2 and all(x < 0 for x in v))
if ps:
for (k, v) in ps:
printf("{n} players, player {k} buzzes at {v}", v=', '.join(str(-x) for x in v))
break
```

Solution: (a) You said buzz for 42 and 91; (b) 19 players took part.

The setter was player number 14.

Here’s a diagram of the game play.

2. Brian Gladman 1 August 2014 at 12:56 pm
```from collections import defaultdict
from itertools import count

def game(players):
# dictionary to record player numbers and buzzes
dct = defaultdict(list)
# player (0 .. n - 1) and direction increment
player, nxt = 0, 1
for k in range(1, 98):
buzz = k % 7 == 0 or 7 in divmod(k, 10)
if buzz:
nxt = -nxt
dct[player + 1].append(k if buzz else 0)
player = (player + nxt) % players
return dct

# increase the  number of players (n) until a solution is found
for n in count(2):
# look for a player who has exactly two buzzes and no numbers
for p, (a, b, *c) in game(n).items():
if a and b and not c:
print("Player {} (of {}) buzzes at {} and {}.".format(p, n, a, b))
break
else:
continue
break
```