Five people, ten handshakes
transcript
Five people at a meeting. Everyone shakes hands once. How many handshakes is that? Do not count them one by one.
The first person shakes four hands. The second has three new ones. Then two. Then one. Four plus three plus two plus one is ten.
Five people make ten handshakes. Ten people make forty five. A hundred people make four thousand nine hundred fifty. Ten times the people means a hundred times the handshakes.
In code, the meeting is two loops. The outer loop takes one person. The inner loop takes everyone after that person. Each pair is met once, and never twice.
The rule is n times n minus one, over two. Check it for five people. Five times four is twenty. Half of twenty is ten. The same rule counts the checks of a pair loop in code.
Do not trust the rule alone. Put a counter on the check and run it. Five ids give ten checks. A thousand ids give 499,500. The run and the rule agree.
Count pairs, not people. Full breakdown in the lecture.