2022 Beaver Computing Challenge
(Grade 9 & 10)
Questions, Answers, Explanations, and Connections
Ana drops six sticks on a table as shown.
Then she picks all the sticks up according to the following rules:
Pick up one stick at a time.
Only pick up a stick if no other stick is on top of it.
In which order did Ana pick up the sticks?
(C)
According to the rules, Ana must pick up the stick on the top of the pile each time. Therefore, she must pick up the sticks as follows.
Sticks Removed | Sticks Remaining |
---|---|
Thus, Ana picked up the sticks in the order shown in Option C.
This task focusses on following operations in sequential order. That is, each stick must be removed from the top of the pile one at a time. After each operation, the state of the pile of sticks changes, and a new stick at the top.
The pile of sticks can be thought of as a simple data structure is used in computer science, called a stack. A stack follows the last iBn, first out or LIFO rule: the item that is placed in last is the first to be removed. Stacks are used frequently in computer science. One such usage is keeping track of operations that can be “undone”, such as edits to a document, browsing history in a browser, or searching through a maze by way of backtracking if a dead end is reached.
Brazil
The mission to explore planet Castor was a success, except for the astronauts losing their personal belongings!
A self-driving robot was sent back to Castor in order to collect all the missing items. The robot can only drive north (\(\uparrow\)), south (\(\downarrow\)), east (\(\rightarrow\)), and west (\(\leftarrow\)). The robot is currently located in the first column on the third row and it has detected the location of seven lost items as shown:
The robot is programmed to identify the item it can get to by driving through the least number of cells. Then it moves to the cell containing that item, and picks the item up. The robot repeats this program until all detected items have been picked up.
Which item does the robot pick up last?
(D)
We will say the distance that the robot is from an item is the number of cells it must drive through to get to that item, including the cell containing that item. Let’s record these values as we trace through the robot’s program in order to determine the item it picks up last.
Current Location | Items Detected (Distance) | Item Picked Up | New Location |
---|---|---|---|
1st column in 3rd row | basketball (3 cells), calculator (7 cells), candy (2 cells), letter (4 cells), pencils (6 cells), scissors (7 cells), shoe (4 cells) | candy | 3rd column in 3rd row |
3rd column in 3rd row | basketball (3 cells), calculator (5 cells), letter (2 cells), pencils (4 cells), scissors (5 cells), shoe (4 cells) | letter | 5th column in 3rd row |
5th column in 3rd row | basketball (5 cells), calculator (3 cells), pencils (2 cells), scissors (3 cells), shoe (6 cells) | pencils | 5th column in 5th row |
5th column in 5th row | basketball (7 cells), calculator (5 cells), scissors (1 cell), shoe (4 cells) | scissors | 6th column in 5th row |
6th column in 5th row | basketball (8 cells), calculator (4 cells), shoe (5 cells) | calculator | 6th column in 1st row |
6th column in 1st row | basketball (4 cells), shoe (9 cells) | basketball | 2nd column in 1st row |
2nd column in 1st row | shoe (5 cells) | shoe | 2nd column in 6th row |
Since all items have been picked up, the last item picked up by the robot is the shoe.
The process that the robot follows is called a greedy algorithm. The key idea in a greedy algorithm is to make a choice at each step based on "local information", regardless of whether there is a better option that might yield a better solution. In this task, the robot makes decisions based only on its current location and the relative distances to the items at this location. It does not take into consideration the overall layout of the items and the distances between pairs of items. That is, instead of trying to look for the global minimum, instead the robot looks for a local minimum.
Greedy algorithms usually produce answers very efficiently, but unfortunately, they do not always guarantee the correct result. For example, the change making problem requires you to make a certain amount of change with the fewest number of coins. If you use a greedy algorithm, this can be done by repeatedly using a coin of as large a value as possible. You stop this process when the desired total change is reached. In most currency systems, this approach will produce the correct minimum number of coins. For example, in Canada, if you used this approach to make change for $1.50, you would end up with one loonie and two quarters which is a total of three coins. However, if Canada introduced a coin worth 75 cents, then you could make change with just two coins in total, and the greedy algorithm will fail.
However, even if a greedy algorithm does not produce the absolute best answer, sometimes they can be used to find a solution that is "good enough". This is called an approximation algorithm. In some cases, solutions that are "good enough and fast" are more desirable than "perfect and extremely slow".
Greedy algorithms do not always correctly solve problems, but when they do, they usually do so very efficiently. For example, the change making problem yields a fast greedy solution: in most currency systems, making a certain amount of change can be done by repeatedly using a coin of as large a value as possible. Stopping this process when the desired total is reached, will always minimize the number of coins used.
Unfortunately, not every greedy algorithm gives the best answer. However, even if a greedy algorithm is incorrect, sometimes they can be used to find a solution that is "good enough". This is called an approximation algorithm.
The area of artificial intelligence, and specifically machine learning, uses greedy algorithms to attempt to find the best approximation to particular problems, such as image classification.
China
In an octagon cipher, groups of letters are placed at each vertex of an octagon. An arrow points from the center of the octagon to a letter group, and the arrow can rotate clockwise.
This octagon cipher is used to create secret versions of words. For each word, the arrow begins pointing to ABC. Then a pair of digits is generated for each letter in the word as follows:
The pairs of digits are then separated by dashes. For example, the secret version of the word TREE is 62-73-42-02.
What is the secret version of the word WATER?
(D) 72-11-62-32-43
We will walk through the process of creating the secret version of the word WATER.
Putting these pairs of digits together gives us 72-11-62-32-43, which is the secret version of the word WATER.
One method of keeping data secret so that unauthorized persons cannot access it is encryption, which is the key area of study in cryptography. Cryptography began as early as 3500 years ago, which simple methods of encryption such as replacing each letter in the message with a different letter, which is known as a substitution cipher. Simple substitution ciphers can be easily decrypted by using frequency analysis: some letters, such as "E" and "T" appear much more than other letters, such as "Q" or "Z" in English text. Therefore, someone reading a long encrypted message can try to guess that the most frequently occurring encrypted letters are probably "E" or "T" and begin to decrypt the message.
An alternative method to a direct substitution cipher is to use rotation-based ciphers, which typically were mechanical devices with various rotors that had sequences of letters, and with each letter, the rotor would move some amount. The most well-known of these sorts of devices is the Enigma machine used to transmit messages during World War II. Similar to this machine in this task, each letter rotates a different amount, such that the sequence of letters "PA" and "SA" (51-31 and 61-21) have the letter "A" encoded with two different values. This type of encryption method is much more difficult to decrypt without knowing the original starting point of the arrow, and is much less vulnerable to frequency analysis.
Many computer systems, such as databases and web browsers, rely on strong encryption methods to prevent unauthorized access to information.
Slovakia
Luis has hexagon pieces in three different colours. Whenever Luis arranges three pieces in a way that resembles an upright triangle, the three pieces must either be all the same colour, or all different colours. These rules do not apply to other three-piece arrangements. In particular:
All colours the same
or all colours different
No colour rules
Luis arranges his hexagon pieces in a way that resembles a tower as shown:
Which hexagon piece must be at the very top?
(A)
Once we know the colours of two hexagon pieces beside each other, we can determine the colour of the piece directly above them. If two pieces side-by-side are the same colour, then the piece above them will be that colour also. However, if two pieces side-by-side are different colours, then the piece above them will be neither colour.
Using this idea, the next row up from the bottom will be:
We can continue building the tower from the bottom up until it is complete:
The hexagon piece at the very top is blue.
This task relies on two fundamental concepts in algorithms: the concept of conditional decisions and repetition.
The conditional decision in this task can be thought of as the following:
IF colour of cell below left is the same as colour of cell below right
THEN
colour of this cell is the same as cell below left
OTHERWISE
colour of this cell is different than both cell below left and cell below right
Conditional statements are often represented in programming languages using if-then-else statements, which allow certain steps to happen only if a given decision/question has a true value.
To solve the entire task, the above steps need to be repeated, from the bottom levels up to the very top level. In computer programs, repetition is often represented as a loop.
Vietnam
Verunka has invented a game to play on her sidewalk. Her sidewalk is 13 squares long and there is a coin on the very last square.
Verunka marks each square (except the last) with either an or an . Then, she begins playing by jumping on the square labelled START and using the following rules:
After landing on a square marked , jump forward 3 squares.
After landing on a square marked , jump backwards 1 square.
Verunka wins if three things happen:
She can always follow the rules (i.e. remain on the sidewalk).
She lands on the square with the coin.
She visits all 13 squares on the sidewalk.
For which marking will Verunka win the game?
(D)
In Options A and C, Verunka will not be able to follow the rules. That is, she will reach an less than 3 squares from the coin.
Verunka lands on the square with the coin in Option B, but she does not visit each square along the way. Specifically, she never visits any squares marked with an .
The correct answer is Option D as shown. The numbers underneath the squares indicate the order in which Verunka visits them.
This task focusses on tracing a simple algorithm on certain input.
The algorithm is fairly straightforward, and can be modelled using a conditional statement: if Verunka lands on an "X" square, then jump forward three squares; if Verunka lands on an “O” square, then jump backwards one square. Many programming languages have the ability to write conditional statements, typically with an if-statement.
In order to trace this algorithm, we must keep track of the state, which will change at each jump. The state for this particular task must keep track of the current square that Verunka occupies as well as all the squares that she has visited. In programming languages, this could be implemented by way of an array, where each cell of the array keeps track of whether or not Verunka has jumped there.
Finally, the input to the algorithm is the sequence of "X" and "O" squares. The input can be viewed as accepted or valid if all squares are visited, and rejected or invalid otherwise. Determining the validity of input, such as password verification, is common occurrence in many software systems.
Czechia
A beaver wants to visit his friend Mary. He doesn’t know which home is hers, but he has the following map of her neighbourhood, which shows homes numbered from 1 to 8, and paths between some of the homes.
Two beavers are considered neighbours if there is a path that connects their homes directly.
The beaver knows the following information.
Mary, Zac, and Pan each have exactly four neighbours.
Niki has exactly two neighbours: Zac and Pan.
What is Mary’s house number?
(C) 4
To solve the problem, we first need to identify the homes with four neighbouring homes. There are three such homes, numbered 4, 5, and 7.
So Mary, Zac and Pan live in homes 4, 5, and 7, in some order.
Next, we identify the homes with two neighbouring homes. There are three such homes, numbered 1, 2, and 6.