You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -48,3 +67,13 @@ In the hiking scenario, the group of four people have to try to solve the proble
48
67
49
68
Imagine that night is now falling fast, and our friends are still stuck in the forest. Add some more detail to the structure diagram to help them survive the night.
*Decomposition* is crucial in any kind of problem breakdown, but especially so in programming. The computer must be told **precisely** what to do, and in what order, so problems must be broken down into discrete parts and each section coded appropriately.
8
26
9
27
Suppose we want to find the ten words most commonly used in a text. How might we go about that?
@@ -33,7 +51,16 @@ Programming rarely works in such a linear fashion. Code generally includes branc
33
51
----------------
34
52
35
53
:::challenge
36
-
## Practice
54
+
## Hiking Preparation Strategy
37
55
38
56
Our friends have finally made it out of the forest and back to civilisation. Their experience, while unpleasant, has not put them off hiking. Draw a structure diagram of the planning they need to do for next time to avert another disaster.
Copy file name to clipboardExpand all lines: episodes/exercise.md
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,7 @@
1
1
---
2
2
title: Exercise
3
-
nav: One
3
+
teaching: 25
4
+
exercises: 20
4
5
---
5
6
6
7
In this exercise, we will see how computational thinking can be used to add up all the numbers between 1 and 200 in our heads, i.e. `1 + 2 + 3 + 4` and so on. We should be able to do this in less than a minute.
Computational thinking is an essential prerequisite for anyone wanting to learn to program computers and write code.
7
24
@@ -40,15 +57,15 @@ There are four essential components of computational thinking:
40
57
-**Algorithms** – developing step-by-step solutions to each part of the problem
41
58
-**Abstraction** – generalising (abstracting) the important detail to make a solution reusable
42
59
43
-
-------
60
+
::::::::::::::::::::::::::::::::::::::::: callout
44
61
45
62
Professor Jeannette Wing raised computational thinking as an important issue for researchers in a 2006 paper. She stated, *"Informally, computational thinking describes the mental activity in formulating a problem to admit a computational solution. The solution can be carried out by a human or machine, or more generally, by combinations of humans and machines."*
46
63
47
64
{alt="brain" width="40%"}
48
65
49
66
Wing believes that computational thinking is just as important a skill for school children to learn as reading, writing and arithmetic. Increasingly, schools are including computational thinking in school curricula.
1.[British Broadcasting Corporation](https://www.bbc.com/) BBC Bitesize. [KS3: Introduction to computational thinking](https://www.bbc.com/bitesize/guides/zp92mp3/revision/1).
Regardless of programming language, **pseudocode** is a useful tool to break coding problems down. Pseudocode helps you list each step of a planned process so your steps are in a logical order before you code.
7
26
8
27
Pseudocode is also a good way to explain your needs to software developers or to run your ideas past people who may not be programmers.
@@ -48,6 +67,40 @@ In a folder, we have 250 image files for which we want to create backup copies b
48
67
49
68
Write some pseudocode of how you might automate this process.
50
69
70
+
::: solution
71
+
72
+
## Potential solution
73
+
74
+
*Steps in the copying process*
75
+
76
+
{alt="Steps in the loop" width="70%"}
77
+
78
+
79
+
### Example code in the Unix shell
80
+
81
+
```{bash, results="hide"}
82
+
for filename in "*.jpg" "*.tif" "*.png"
83
+
do
84
+
cp $filename backup-$filename
85
+
echo $filename backup-$filename
86
+
done
87
+
```
88
+
89
+
90
+
{alt="Loop as it would be written in the Unix shell" width="90%"}
91
+
92
+
*Notes*
93
+
94
+
In the code example above, the loop will run through the folder creating back up copies of all the files with the file extension `.jpg`. As each file is copied, each original filename and the filename of each new file will be printed to the screen.
95
+
96
+
Then the loop will restart and repeat the process for all the files with the file extension `.tif`, again printing the original filenames and the filenames of the new files to the screen.
97
+
98
+
Then the loop will restart and run through the folder a third time, creating back up copies of all the files with the file extension `.png`, again printing the original filenames and the filenames of the new files to the screen.
99
+
100
+
The loop will then stop, as there are no more variables to work on.
101
+
102
+
:::
103
+
51
104
:::
52
105
53
106
::: challenge
@@ -58,6 +111,23 @@ We have a large folder of files left over from a project that is now finished. T
58
111
59
112
Write some pseudocode of how you might automate this process.
60
113
114
+
::: solution
115
+
116
+
## Potential solution
117
+
118
+
*Steps in the moving process*
119
+
120
+
1. Identify the different file types in the folder.
121
+
2. Create new folders to house the different file types.
122
+
3. Create a series of loops to work through the folder, file type by file type, moving the files to the correct folders.
123
+
4. Once the final loop has run, delete all remaining files left within the main folder.
124
+
5. Print filenames to the screen as the loop runs to verify it is working as required.
125
+
126
+
*Using a shell script to automate the work*
127
+
128
+
The task above could be fully automated using a shell script. A shell script is a text file containing a sequence of commands for a UNIX-based operating system that allows those commands to be run in one go, rather than by entering each command one at a time. Scripts make task automation possible. The script would contain the commands to do the tasks listed above, such as folder creation, file movement using loops, file deletion and so on. The benefit of shell scripts is that the code they contain can be re-used or adapted for similar tasks.
129
+
130
+
:::
61
131
:::
62
132
63
133
::: challenge
@@ -107,4 +177,13 @@ Suppose you write that file movement script and it works a treat.
107
177
Why not get it to run every month to tidy up folders that invariably become messy over time, e.g., your computer's `Downloads` folder?
108
178
109
179
Or, suppose you use a file naming convention that starts with `YYYY-MM-DD`. Why not run a script annually to sort and organize your documents by year?
0 commit comments