## Teaser 2995: Pub celebration

**From The Sunday Times, 16th February 2020** [link]

While celebrating with friends in the pub, it was my round, and I worked out the number of ways that I could get everybody else’s drink wrong. I could remember the drinks (and they all wanted different drinks), but not who wanted which drink.

More friends arrived (there were fewer than twenty of us in total), and everyone still wanted different drinks. Again assuming that I could remember the drinks but not who wanted which drink, I worked out the number of ways that I could get everybody else’s drink wrong, and found that the number was 206 times the first number. Fortunately, it was no longer my round!

What was the second number?

[teaser2995]

## Jim Randell 5:07 pm

on14 February 2020 Permalink |The number of

derangements[ @wikipedia ] of a set ofnobjects is known assubfactorial(n), denoted!n. (See:Teaser 2779).This Python program calculates

!nrecursively. It runs in 72ms.Run:[ @repl.it ]Solution:The second number is 1854.Initially the setter has 4 friends (!4 = 9), so there were 5 people in the group.

After the additional people arrived the setter had 7 friends (!7 = 1854 = 206 × 9), so there were 8 people in the group.

Manually we can use use the following recurrence relation to count derangements:

This makes it easy to calculate values on a calculator, and is enough to find that

d(7) ÷ 206 = d(4).However beyond

d(13) = 2290792932my physical calculator runs out of digits. The Calculator app on my laptop has just enough digits to “manually” determine thatd(19)(which has 17 digits) is also divisible by 206, but the result of the division is not advalue we have already encountered, so the solution is unique. (Of coursePythonhas built-inbigintsupport, so doesn’t have a problem with the larger numbers).LikeLike

## Jim Randell 9:24 am

on15 February 2020 Permalink |And here is a solution that calculates

!niteratively.Run:[ @repl.it ]We only need to check for the smaller case when

!nis divisible by 206, which only happens in 2 non-trivial cases for the range of values applicable to the puzzle.The program also accumulates the sequence of subfactorials in the array [[

`ds`

]]. (See OEIS A000166 [ @oeis.org ]).LikeLike

## GeoffR 1:09 pm

on17 February 2020 Permalink |LikeLike