← all problems

handshakes 🌶️🌶️

At a meeting every person shakes hands once with every other person. Write a method handshakes that takes the number of people (0 or more) and returns how many handshakes there are. Count them with nested loops: for each person, count the handshakes with the people who come after them.

For example, handshakes(3) is 3, handshakes(5) is 10, and handshakes(1) is 0.