C3.1 Solve problems and create computational representations of mathematical situations by writing and executing code, including code that involves sequential, concurrent, and repeating events.

Skill: Solving Problems Using Computational Methods


Coding can be used to automate tasks and visualize mathematics to facilitate problem solving. By its very nature, coding lends itself to trial and error, giving students the opportunity to solve problems by learning from their mistakes. This allows students to ask "what if?" questions.

For example, the student might ask, "What will happen if I roll a die 1,000 times?"

A thousand rolls of the die is a repetitive and time-consuming task, but with a few lines of code, this task takes only a few seconds:

Control block stating, “Repeat 1000.”Inside are 2 nested blocks.Variable block stating “Set “Die” to  pick random 1 to 6”.Lists block stating, “add Die to throws.”

In this pattern, a variable named DE will have a random value assigned from 1 to 6, the options resulting from the roll of a six-sided die. Each result is added to a list named LANCERS. This code takes less than a second to execute, and the student is provided with a list of roll results, which will be used to perform data analysis.

Skill: Representing Mathematical Situations in Computational Ways


Coding can be used as a representational tool in the same way as manipulatives. By using written blocks or commands, very complex mathematical situations can be modeled and visualized, which can make very abstract concepts concrete.

For example, loops are excellent tools for representing multiplication through repeated addition. Thus, the student could interpret multiplication by coding an array as follows:

image Blocks of code:6 attached blocks:Events block stating, “starts on green flag when clicked”.Motions blocks stating, “go to x-200 y –150’’. Variables block stating ‘’set row to zero’’. Looks blocks stating ‘’show’’. Events block stating ‘’repeat six”. Inside are 11 nested blocks. Controls block stating “create clone of myself’’.Motions block stating “move ‘70’ steps”.Controls block stating “create clone of myself’’.Motions block stating “move ‘70’ steps”.Controls block stating “create clone of myself’’.Motions block stating “move ‘70’ steps”.Controls block stating “create clone of myself’’.Motions block stating “move ‘70’ steps”.Controls block stating “go to x: ‘-200’ y” ‘-150’”. Variables block stating “change row by ‘1’.Motions block stating “change y by ‘30’ motions block ‘row’”Looks block stating ‘hide’.

This code will make a six row arrangement of four "clones" of the sprite in question. However, there are several combinations of blocks to represent a multiplication with a product of 24, allowing students to represent the same situation in multiple ways.

Skill: Writing Code


Writing or editing a code consists of placing instructions in a specific order, following the syntax of a programming language. Writing code can be similar to writing a text. Pseudocode writing, on the other hand, consists of writing code instructions in the familiar language. Block coding can make it easier to follow the syntax by using different block shapes and colours.

Repeating patterns are a great opportunity to practice writing code with loops, as they require few variables and starting conditions. The student could define their pattern using move, look, sound blocks, etc., and then use loops to extend the sequence. The pseudocode below represents an example of a repeating pattern core, which uses the costumes of a sprite to create the pattern.

When the code is executed :

Repeat 6 times:

Choose the "red" suit

Make a copy of the sprite

Advance 20 steps

Choose the "blue" suit

Make a copy of the sprite

Advance 20 steps

Choose the "yellow" suit

Make a copy of the sprite

Advance 20 steps

Choose the "blue" suit

Make a copy of the sprite

Advance 20 steps

The result of this code would be six patterns of an ABCB sequence.

Skill: Executing Code


Code execution is the step where the code sequence is read and compiled by the computer. It is at this stage that a functional code will give the desired result or output (and a non-functional code will give a different output or no output). In block coding, code execution is often done by means of a button in the interface, whereas text-based programming languages require precise compilation software that essentially translates the code from the programming language into the machine language.

Here are some examples of run buttons for block coding software:

Examples of coding execution button.

Source: Microbit.

Examples of coding execution button.

Source : Scratch.

Knowledge: repetitive events


Repeating events are events that repeat themselves. In coding activities, loops are used in code to repeat instructions. Here are some examples of blocks that represent loops:

Scratch Jr

Scratch

Make:Code

Control blocks ‘repeated four times’. Control blocks ‘repeated four times’. Control blocks ‘repeated four times’.


In each case above, the code inside the loop would be repeated four times.

Because the loop is analogous to multiplication in nature, the use of repeating events is ideal for solving problems involving multiplicative thinking.

We can first use the loop to represent a multiplication. Let's take the following code:

Blocks of code:Events block stating “Start on green flag.”Control block stating ‘’repeat 4’’.Inside are 2 nested blocks.Motions block “move ‘60’ steps.” Controls block stating ‘’create a clone of myself’’.

The behavior of the sprite according to this code will be to move 60 steps (in this context, one pixel represents one step), and to make a copy of itself. This behavior will be repeated four times, as defined by the loop. The code is thus a representation of the 1 × 4 operation, and the result is represented on the screen after clicking on the green flag.

Two picture screen from a computer. The first picture screen is an apple and title ‘before clicking on the green flag’’. The second screen shot has four apples and title ‘’after clicking on the green flag.

By adding sprites, the operation that is represented can be changed. In this example, there are three sprites, Apple_1, Apple_2 and Apple_3, each with identical code.

Blocks of code:Events block stating “Start on green flag.”Control block stating ‘’repeat 4’’.Inside are 2 nested blocks.Motions block “move ‘60’ steps.” Controls block stating ‘’create a clone of myself’’.

When the code is executed by clicking on the green flag, an array representation of the 3 × 6 operation appears, i.e. three rows of six apples.

Blocks of code:Events block stating “Start on green flag.”Control block stating ‘’repeat 4’’.Inside are 2 nested blocks.Motions block “move ‘60’ steps.” Controls block stating ‘’create a clone of myself’’.