Know that numbers can be aggregated into data structures such as lists.
Understand that algorithms are a series of steps or instructions for solving a problem such as sorting and shuffling a list of numbers.
Be able to use data structures and built-in algorithms as part of Sonic Pi composition, using comments to explain what is happening.
Numbers as a kind of data.
Introduction to lists.
Playing a list of numbers.
Introduction to sorting.
Sorting and shuffling a list of numbers.
Pupils should be asked what kind of information they have been using in the previous lessons; in other words, the things they’ve been able to change. They have been able to change the time to sleep and the note to play. Ask them what kind of information this is, the answer being that they are all numbers. Explain that a number is a kind of data, and there are many others that computers may understand.
Explain to the pupils that although numbers are one of the most useful forms of data, it’s also very handy to represent a list of numbers. Ask them if they can think of any things that could be represented by a list of numbers; for example, the finish times of runners in a race, the numbers drawn in the lottery and the notes of a bass line.
Invite the pupils to enter the following code into a new worksheet and press play:
Explain that play_pattern is similar to play except instead of taking a number representing the note to play, it takes a list of numbers to play one after the other. This list of numbers has special syntax to tell the computer that it’s a list. Firstly, it has to start with a [ and end with a ]. Secondly, each number in the list has to be separated from the other numbers with a comma.
Invite the pupils to write their own lists, choosing different numbers and different lengths of numbers, for example:
Once they’ve had a short play with this, invite them to form a line and hand out the number cards (in no particular order), so each pupil in the line holds just one card. Explain that they have formed a list of numbers and that there are useful things that you can do with this. One example is sorting the numbers numerically, so that the smallest numbers are first and the largest last. Introduce the word 'algorithm' as a method for solving such problems.
Next, explain that we will explore a simple sorting algorithm: bubble sort. Start at the left hand side of the line and ask the first two pupils to compare their numbers. If they are in the right order do nothing, otherwise ask the pupils to swap. Then continue to the second and third pupils, and compare and swap again if necessary. Continue down the line. If at least one pair has swapped, start at the beginning of the line and repeat. If no pairs have swapped, the list is sorted.
Explain that most programming languages provide many such algorithms to make programming easier, and to reduce the amount of work you have to do as a programmer. Ask the pupils to type the following code: