Skip to content
PiRush

LearnLogic

Counting cleverly

Handshakes at a party, squares in a grid, socks in the dark, the fewest coins, and finding a heavy coin with a balance.

Some questions ask "how many?" when there are far too many things to count one by one. How many handshakes at a party of 30 people? How many squares hide in a grid? Clever counting means finding a short way to get the total without missing any and without counting any twice. A second kind of question asks how many you need to be sure of something. For those, the trick is to imagine the unluckiest thing that could happen. Both ideas are used every day by people who write computer programs and plan sports leagues.

Handshakes at a party

There are 5 people at a party. Each one shakes hands once with every other person. How many handshakes are there? Each person shakes hands with the 4 others, so it looks like 5 × 4 = 20. But when Ana shakes hands with Ben, that one handshake is counted twice: once for Ana and once for Ben. So divide by 2.

Remember

handshakes = (n(n − 1))/2

n is the number of people. Each person shakes n − 1 hands, and every handshake is counted twice.

Example 1

There are 9 people at a meeting. Each one shakes hands once with every other person. How many handshakes are there?

  1. Each of the 9 people shakes 8 hands: 9 × 8 = 72.
  2. Every handshake was counted twice: 72 ÷ 2 = 36.

Answer: 36 handshakes

Sometimes the question goes the other way: you know the handshakes and must find the people. Double the number of handshakes. Then look for two whole numbers next to each other that multiply to give it. The bigger one is the number of people.

Example 2

At a party, everyone shakes hands once with everyone else. There are 55 handshakes. How many people are there?

  1. Double it: 55 × 2 = 110.
  2. Which two numbers next to each other multiply to 110? 11 × 10 = 110.
  3. So there are 11 people. Check: 11 × 10 ÷ 2 = 55.

Answer: 11 people

People23456789101112
Handshakes1361015212836455566

Squares in a grid

A big square is cut into a 3 by 3 grid of small squares. How many squares are there in total? Not just 9: the small squares can join to make bigger squares. Count by size.

A 3 by 3 grid. Besides the 9 small squares, any 2 by 2 block of four small squares is also a square, and so is the whole grid.
  • 1 by 1 squares: 3 in each row and 3 rows, so 3 × 3 = 9.
  • 2 by 2 squares: a 2 by 2 square can start in 2 places across and 2 places down, so 2 × 2 = 4.
  • 3 by 3 squares: only the whole grid, so 1.
  • Total: 9 + 4 + 1 = 14.

Remember

squares in an n by n grid = 1² + 2² + 3² + ... + n²

Add the square numbers from 1 up to the size of the grid.

Example 3

A big square is divided into a 5 by 5 grid of small squares. How many squares of any size are there?

  1. 1 by 1: 5 × 5 = 25.
  2. 2 by 2: 4 × 4 = 16.
  3. 3 by 3: 3 × 3 = 9.
  4. 4 by 4: 2 × 2 = 4.
  5. 5 by 5: 1.
  6. Total: 25 + 16 + 9 + 4 + 1 = 55.

Answer: 55 squares

Socks in the dark

A drawer has 8 red socks and 8 blue socks. It is dark, so you cannot see the colors. How many socks must you take to be sure of two of the same color? Think of the unluckiest case, the worst case. With 2 socks, you might get one red and one blue: no pair. But the 3rd sock must be red or blue, so it matches one of them. The answer is 3.

Remember

To be sure of 2 of the same color: number of colors + 1

In the worst case you get one of each color first. The next one must match.

This is called the pigeonhole principle. A pigeonhole is one small box in a wall of boxes. If 13 pigeons fly into 12 holes, at least one hole has two pigeons. In the same way, if 13 people are in a room, at least two of them have their birthday in the same month, because there are only 12 months.

Example 4

A drawer has 6 red, 6 blue, 6 green and 6 yellow socks. It is dark. How many socks must you take to be sure of two of the same color?

  1. The worst case: the first 4 socks are all different colors.
  2. There are only 4 colors, so the 5th sock must match one of them.

Answer: 5 socks

Being sure of something harder

The same worst-case thinking answers harder questions. Ask: what is the longest I could go without getting what I want? Then take one more.

Example 5

A drawer has 7 black socks and 3 white socks. It is dark. How many socks must you take to be sure of getting 2 white ones?

  1. The worst case: you take all 7 black socks first.
  2. After that, every sock is white. You need 2 of them.
  3. Total: 7 + 2 = 9.

Answer: 9 socks

Gloves are a little harder, because a glove is a left one or a right one. A drawer has 5 pairs of black gloves and 5 pairs of white gloves. How many must you take to be sure of a left and a right glove of the same color? In the worst case, the first 10 gloves are all left gloves: 5 black and 5 white. There are no more left gloves, so the 11th is a right glove. Whatever its color, there is a left glove of that color already in your hand. The answer is 11.

The fewest coins

You must pay an exact amount with as few coins as possible. The plain method is to take the biggest coin that fits, again and again, until nothing is left.

Example 6

You have many coins of 1, 2, 5, 10, 20 and 50 cents. What is the fewest coins you need to pay exactly 87 cents?

  1. 50 fits: 87 − 50 = 37 left.
  2. 20 fits: 37 − 20 = 17 left.
  3. 10 fits: 17 − 10 = 7 left.
  4. 5 fits: 7 − 5 = 2 left.
  5. 2 fits: nothing left.
  6. Coins: 50 + 20 + 10 + 5 + 2 = 87.

Answer: 5 coins

This works for the coins most countries use. But with unusual coins it can fail. With coins of 1, 10 and 25 cents, the biggest-first method pays 30 cents as 25 + 1 + 1 + 1 + 1 + 1: 6 coins. Three 10-cent coins make 30 with only 3.

Finding the heavier coin with a balance

You have 9 coins that look the same, but one is a little heavier. A balance scale has two pans and tells you which side is heavier, or that they weigh the same. What is the fewest weighings that always finds the heavy coin? Most people split the coins in half. The better idea is to split them into three groups, because one weighing has three possible results: the left pan is heavier, the right pan is heavier, or they balance.

Example 7

You have 9 coins. One is heavier. Find it with the fewest weighings.

  1. Make 3 groups of 3. Put one group on each pan and keep one group off.
  2. If one pan goes down, the heavy coin is in that group. If they balance, it is in the group you kept off.
  3. Now you have 3 coins. Put 1 on each pan and keep 1 off.
  4. The pan that goes down holds the heavy coin. If they balance, it is the one you kept off.

Answer: 2 weighings

Each weighing cuts the number of possible coins to a third. So 1 weighing can handle 3 coins, 2 weighings 9 coins, 3 weighings 27 coins, and 4 weighings 81 coins. For a number in between, use the next one up: 8 coins still need 2 weighings (weigh 3 against 3; if they balance, weigh the last 2 against each other), and 10 coins need 3.

Weighings1234
Most coins392781

Try it yourself

  1. 1.There are 11 people at a party. Each one shakes hands once with every other person. How many handshakes are there?

    Show the answer

    55

    11 × 10 = 110, and every handshake is counted twice: 110 ÷ 2 = 55.

  2. 2.At a party there are 36 handshakes, one between every two people. How many people are there?

    Show the answer

    9

    Double it to 72, and 9 × 8 = 72. Check: 9 × 8 ÷ 2 = 36.

  3. 3.How many squares of any size are there in a 6 by 6 grid?

    Show the answer

    91

    36 + 25 + 16 + 9 + 4 + 1 = 91.

  4. 4.A drawer has socks in 5 colors, 10 of each. In the dark, how many must you take to be sure of two of the same color?

    Show the answer

    6

    The worst case is 5 different colors. The 6th sock must match one of them.

  5. 5.You have many coins of 1, 5, 10 and 25 cents. What is the fewest coins that pay exactly 68 cents?

    Show the answer

    7

    25 + 25 + 10 + 5 + 1 + 1 + 1 = 68. Using the biggest coin that fits each time works for these coins.

  6. 6.You have 30 coins, and one is a little heavier. What is the fewest weighings on a balance that always finds it?

    Show the answer

    4

    3 weighings can handle at most 27 coins. 30 is more than 27, so you need 4, which can handle up to 81.

Ready to test yourself?

Play Logic: 20 seconds per question, and it gets harder as you go.