CEMC Banner

Problem of the Week
Problem A and Solution
Gathering Treasure

Problem

Genevieve is making a video game where players need to trade gems in order to get to the next level. The gems in the game are emeralds emerald, diamonds diamond, and rubies ruby. In the first level, players make three trades of their gems, as shown in the diagram, until they have at least \(10\) rubies ruby.

A description of the diagram follows.

  1. How many of each gem will a player have when they finish the first level?

  2. How many trades in total will a player have made when they finish this level?

Solution

  1. The player starts with only \(1\) emerald, so does not have at least \(10\) ruby, and therefore needs to make trades. The gems after the first three trades are shown.

    \(1\) emerald \(\rightarrow\) \(2\) diamond \(\rightarrow\) \(3\) ruby \(\rightarrow\) \(1\) emerald, \(2\) ruby

    The player still does not have at least \(10\) ruby, so needs to make trades. The gems after the next three trades are shown.

    \(1\) emerald, \(2\) ruby \(\rightarrow\) \(2\) diamond, \(2\) ruby \(\rightarrow\) \(5\) ruby \(\rightarrow\) \(1\) emerald, \(4\) ruby

    The player still does not have at least \(10\) ruby, so needs to make trades. However, we can start to see a pattern. After each group of three trades, the player ends up with \(2\) ruby more than they started with. So after the next three trades, the player will have \(1\) emerald and \(6\) ruby, then \(1\) emerald and \(8\) ruby, and then \(1\) emerald and \(10\) ruby. At this point they will have at least \(10\) ruby, so will have finished the level. Therefore, when a player finishes the first level, they will have \(1\) emerald and \(10\) ruby.

  2. Each time the player makes the three trades, they earn \(2\) ruby. Since they started with \(0\) ruby, need \(10\) ruby to finish the level, and \(2 \times 5 = 10\), it follows that they must make the three trades \(5\) times. Therefore, in total, they must make \(3 \times 5 = 15\) trades in the first level.

Teacher’s Notes

The diagram that describes the trades and the movement between them is similar to a flowchart that describes a loop in computer science.

A loop in coding allows you to repeat instructions. In this example, you repeat a set of three trades until you have enough rubies to stop. This is an example of a conditional loop since the repetition continues until some condition is met.

When coding, using conditional loops can be tricky since it is possible that the stopping condition might never be met. This is called an endless loop. One way loops might continue forever is if the values being checked in the stopping condition never change. In our problem, we are guaranteed that the loop will stop eventually because we can show that the number of rubies increases each time it repeats.