At a party of 8 people, everyone shakes hands with every other person exactly once. How many handshakes occur in total?
At a party of 8 people, everyone shakes hands with every other person exactly once. How many handshakes occur in total?
At a party of 8 people, everyone shakes hands with every other person exactly once. How many handshakes occur in total?
28 handshakes.
A handshake is an unordered pair of two distinct people, so the count is the number of ways to choose 2 people from 8: the binomial coefficient C(8, 2).
C(n, 2) = n(n − 1) / 2
For n = 8: 8 × 7 / 2 = 56 / 2 = 28.
Why divide by 2. Person 1 can shake with 7 others, person 2 with 7 others, and so on, giving 8 × 7 = 56. But this counts each handshake twice — "A shakes B" and "B shakes A" are the same event — so you divide by 2, leaving 28.
Equivalent view (the running sum). The first person shakes 7 hands; the second adds 6 new ones; the third adds 5; and so on down to the last pair: 7 + 6 + 5 + 4 + 3 + 2 + 1 = 28. This is the 7th triangular number, T₇ = 7×8/2 = 28.
General rule. For any party of n people the answer is n(n − 1)/2 (e.g., 10 people → 45, 12 people → 66).
from math import comb
print(comb(8, 2)) # 28
Sources: