# Enigmatic Code

Programming Enigma Puzzles

## Enigma 137: Dominoes galore

From New Scientist #1281, 26th November 1981 [link]

The standard set of dominoes includes pieces up to the double 6, but at our school we have sets which go higher and lower than 6. So, for example, we have a 7-set which includes all pieces up to the double 7, etc, etc. Bill was playing with one set and Ben with another.

Bill said, “My set has the same total number of spots as your set has dominoes.”

Ben agreed and added, “But if I had the set of the next number up, and instead of your set you had the one of the next number down, then my set would have twice as many dominoes as yours has spots.”

What sets do Bill and Ben have? (e.g. 3-set and 24-set).

[enigma137]

### One response to “Enigma 137: Dominoes galore”

1. Jim Randell 20 October 2013 at 9:39 am

This Python program runs in 32ms.

```from enigma import T, printf

# generate the number of dominoes and spots in an n-spot set
def generate():
(n, d, s) = (0, 1, 0)
while True:
yield (n, d, s)
n += 1
d += n + 1
s += 3 * n * (n + 1) // 2

# map n -> d, n -> s, s -> n
(n2d, n2s, s2n) = (dict(), dict(), dict())
for (n, d, s) in generate():
printf("[n={n} d={d} s={s}]")
# suppose n = ben + 1
ben = n - 1
# is there a value for (bill - 1) with half as many dominoes as
# (ben + 1) has spots
(d2, r) = divmod(d, 2)
if r == 0 and d2 in s2n:
bill = s2n[d2] + 1
# and bill's number of spots is the same as ben's number of dominoes
if bill in n2s and n2s[bill] == n2d[ben]:
printf("bill = {bill}, ben = {ben}")
break

# record the values
(n2d[n], n2s[n], s2n[s]) = (d, s, n)
```

Solution: Bill has a 5-set. Ben has a 13-set.

This site uses Akismet to reduce spam. Learn how your comment data is processed.