University of Waterloo Logo and CEMC Banner

2021 Beaver Computing Challenge
(Grade 7 & 8)

Questions, Answers, Explanations, and Connections


Part A

Butterflies

Story

A beaver is photographing butterflies, but after each photo is taken, half the butterflies fly away.

The first photo has 64 butterflies in it and the last photo has 2 butterflies in it.

Question

How many photos did the beaver take?

  1. 6
  2. 63
  3. 4
  4. 32

Answer

(A) 6

Explanation of Answer

We are told that the first photo has 64 butterflies in it. Since half the butterflies fly away after each photo is taken, we can record how many butterflies are in each photo.

Photo Number Number of Butterflies
1 64
2 32
3 16
4 8
5 4
6 2

We see that the photo with 2 butterflies in it is photo number 6. Therefore, the beaver took 6 photos.

Connections to Computer Science

In order to move from 64 butterflies to one butterfly, we need to cut the number in half 6 times. If we started with 128 butterflies, we would need to cut the number in half 7 times before reaching one butterfly, and if we started with 256 butterflies we would need to cut the number in half 8 times before reaching one butterfly.
This process of cutting by half each time decreases the problem size exponentially. There are many natural processes that either grow or shrink exponentially: how an invasive species spreads and how a radioactive element decreases its radioactivity are two examples. This idea is used by computer scientists to design algorithms which use the divide and conquer technique: each major step of the algorithm reduces the size of the problem by half. These sorts of algorithms are very efficient because they can take very large inputs and produce an answer very quickly. One famous example of this idea is binary search in a sorted list of elements.

Country of Original Author

Canada

Overlapping Coins

Story

Emil has six different coins.

Emil placed the six coins on a table, one at a time. Some coins were placed on top of other coins so that they overlap as shown.

Coins A, B, C, D, E, and F are placed in a pile in three levels. Coin D is on the bottom level. Coins C and F are on top of Coin D in the middle level, with Coin C on top of Coin F. Coins A, B and E are on the top level, with coin E on top of Coin B and Coin A on top of Coin E.

Question

Which coin was the fourth coin that Emil placed on the table?

  1. Coin A
  2. Coin B
  3. Coin C
  4. Coin D

Answer

(B) Coin B

Explanation of Answer

To determine the correct answer, we reverse the process.

The pile of six coins.

Notice that the coin A in the bottom-left corner is the only coin that has no other coins on top of it. This means it must have been placed on the table last and was therefore the sixth coin to be placed. Before this coin was placed, the coins on the table must have looked like this:

Five coins B, C, D, E, and F are placed in a pile in three levels. Coin D is on the bottom level. Coins C and F are on top of Coin D in the middle level, with Coin C on top of Coin F. Coins B and E are on the top level, with coin E on top of Coin B.

Now the only coin that has no other coins on top of it is the coin E. This coin must have been placed second to last and was therefore the fifth coin to be placed. Before this coin was placed, the coins on the table must have looked like this:

Four coins B, C, D, and F are placed in a pile in three levels. Coin D is on the bottom level. Coins C and F are on top of Coin D in the middle level, with Coin C on top of Coin F. Coins B is on the top level.

Now the only coin that has no other coins on top of it is the coin B. This coin must have been placed third to last and was therefore the fourth coin to be placed.

Continuing this process, we find that the coins were placed on the table in the following order:

  1. Coin D
  2. Coin F
  3. Coin C
  4. Coin B
  5. Coin E
  6. Coin A

Connections to Computer Science

The coins in the picture are laid in a sequence, and the order of the sequence matters.

There are many sequences where the order matters. For example, when getting dressed, putting on shoes should come after putting on pants.

Another example is describing to a computer how to draw a picture. Drawing a circle, then two dots, and then a curved line, will produce a smiley face, as shown in the picture below.

If the order was different, and the circle was drawn last, the two dots and curved line would have been hidden behind the circle.

Computers internally usually also work sequentially. Most computer programs are written so that first one action and then another action happens. So a computer program for drawing a smiley face could look like this:

Country of Original Author

Czech Republic

Arranging Objects

Story

A board is divided into squares and a different object is placed in each square as shown.

A three by three grid. From left to right, the squares in the first row have the earth, a tree, and an apple, the second row has a flower, a mushroom, and a star, and the third row has the sun, a ladybug, and a clover.

A swap exchanges the locations of two objects. Three swaps occur in this order:

  1. The flower swaps with the tree.
  2. The tree swaps with the ladybug.
  3. The ladybug swaps with the star.

Question

What is the location of the star after the last swap?


  1. First square in the second row.

  2. Third square in the second row.

  3. Second square in the first row.

  4. Second square in the third row.

Answer

(A)
First square in the second row.

Explanation of Answer

Here is the state of the board after each swap:

Start

First row: earth, tree, apple. Second Row: flower, mushroom, star. Third row: sun, bug, clover.

Swap 1 Flower and Tree

First row: earth, flower (highlighted), apple. Second Row: tree (highighted), mushroom, star. Third row: sun, bug, clover.

Swap 2 Tree and Ladybug

First row: earth, flower, apple. Second Row: bug (highighted), mushroom, star. Third row: sun, tree (highlighted), clover.

Swap 3 Ladybug and Star

First row: earth, flower, apple. Second Row: star (highighted), mushroom, bug (highlightted). Third row: sun, tree, clover.

If you compare the locations of the objects at the beginning, with the locations of the objects after the last swap, you can see that the star is now in the original location of the flower.

Another way to see this final result is to think about trading goods at a market. Suppose you bring a flower and you trade it for a tree. Then you trade your tree for a ladybug. Then you trade your ladybug for a star. The item you end up with is the same as if you traded your flower for a star directly.

Connections to Computer Science

This task focuses on the concept of swapping values between two variables. In computer programming, a variable is a memory location that can hold information. Swapping involves exchanging the values of two variables.

For example, suppose A is a variable that holds the value “18” and B is another variable that holds the value “42”. After a swap, variable A will hold “42” and variable and B will hold “18”.

In most programming languages, a temporary variable is needed to swap values between two variables. For example, if there was a temporary variable T, the following three steps would swap the values between A and B:

  1. Give T the value of A.
  2. Give A the value of B.
  3. Give B the value of T.

One of the most common uses of swapping in computer science is in sorting, where a collection of data it put into either ascending or descending order.

Country of Original Author

India

Genetic Data

Story

A genetic scientist is conducting experiments. Each experiment involves a condition followed by a sequence of letters. The condition includes two numbers and a target letter. An experiment is flagged if the number of times the target letter appears in the sequence is between the two numbers (inclusive).

Example 1

The condition has the numbers 1 and 2, and the target letter A. The sequence of letters is A T G C.

This experiment is flagged because the number of times the target letter A appears in the sequence ATGC is 1 which is between 1 and 2 (inclusive).

Example 2

The condition has the numbers 3 and 8, and the target letter T. The sequence of letters is A T G T.

This experiment is not flagged because the number of times the target letter T appears in the sequence ATGT is 2 which is not between 3 and 8 (inclusive).

Question

How many of the following four experiments will be flagged?

A description of the four experiments follows.

  1. 1
  2. 2
  3. 3
  4. 4

Answer

(C) 3

Explanation of Answer

The first experiment is flagged because the number of times the target letter T appears in the sequence T T T T T T T is 7 which is between 2 and 8 (inclusive).

The second experiment is not flagged because the number of times the target letter C appears in the sequence A G C T A C T A C is 3 which is not between 1 and 2 (inclusive).

The third experiment is flagged because the number of times the target letter A appears in the sequence T C G C T G C is 0 which is between 0 and 2 (inclusive).

The fourth experiment is flagged because the number of times the target letter G appears in the sequence G A T G T A G C T is 3 which is between 1 and 3 (inclusive).

Three of the four experiments are flagged.

Connections to Computer Science

The concept of pattern recognition is a very important one in computer science. The key goal of pattern recognition is to determine if some input, perhaps text or an image, matches or contains a particular pattern. For example, given a large body of text, such a collection of textbooks or entire webpages, determine if a certain word or phrase appears.

DNA can be described as a very long sequence of the letters A, C, G, T. In humans, there are about 3 billion such letters describing DNA. A particular pattern would be a sequence of letters that is known to indicate a certain genetic condition, such as an increased likelihood of a specific disease.

One very common technique to describe patterns in text is the use of regular expressions. An example of a regular expression for Canadian Postal codes would be (A-Z)(0-9)(A-Z)(0-9)(A-Z)(0-9). This expression indicates that the first, third, and fifth characters must be uppercase letters, and the second, fourth, and sixth characters must be a single digit. Regular expressions like this are used in text editors for advanced “search and replace” functions.

Country of Original Author

Portugal

Volcanoes

Story

In the map shown, Dino can follow roads and can climb up and over volcanoes unless they are erupting.

A description of the map follows.

Because two volcanoes are erupting, Dino cannot get from point \(P\) to point \(Q\).

Question

Which two volcanoes are erupting?

  1. Volcanoes 1 and 2
  2. Volcanoes 3 and 4
  3. Volcanoes 1 and 4
  4. Volcanoes 2 and 4

Answer

(D) Volcanoes 2 and 4

Explanation of Answer

Since Dino cannot climb up and over an erupting volcano, a road to or a road from an erupting volcano is not helpful (at least up to the point where it intersects another road).

In the following image all roads to and from volcanoes 2 and 4 have been removed. Notice that in this situation it is not possible for Dino to get to point \(Q\) from point \(P\).

Paths connect point P to volcano 1 and volcano 3 to point Q. There are no other paths connecting volcanoes 1, 2, 3, and 4 and points P and Q.

Using the same approach we can see that a route from \(P\) to \(Q\) does exist for the other three options.

Erupting Volcanoes Map Route
(from \(P\) to \(Q\))
1 and 2 Paths connect point P to volcano 4, volcano 4 to volcano 3 and point Q, and volcano 3 to Q. Route over volcano 4 exists
3 and 4 Paths connect point P to volcanoes 1 and 2, volcano 1 to volcano 2, and volcano 2 to point Q. Route over volcano 2 exists
1 and 4