Awesome Algorithms and Creative Coding Book
Awesome Algorithms and Creative Coding Book
Firs
Fi
F rst pu
publ
blis
ishe
hedd in 2
201
0155 by Way
ayla
land
nd
Copy
Co
C pyri
righ
ghtt © Wa
W yly an
andd 20
2015
15
Waylan
Wayl and
d
338
33 8 Eu
Eust
ston
on R
Roa
oad
d
Lo
ond
ndon
on NW1 3BH
Waylan
Wayl andd Au
Aust
stra
ralilia
a
Leve
Le el 17
7/2
/207
07 K
Ken
entt St
Stre
reet
et
Sydn
Sy dney
ey,, NS
NSWW 202000 00
A l riigh
Al ghts
ts res
eser
erve
vedd
Commis
Comm issi
sion
onin
ing g Ed
Edit
itor
or: De
Debbbbie
ie
e Foyy
Proj
Projec
ectt Ed
Edititor
or:: Ca
Caro
roli
line
ne W
Wesest (B
Blu
lue
e Dr
Drag
agon
onflfly
y Lt
Ltd.
d..)
Desi
De
esi
ssign
gner
g er:: Ma
e MarkrkkL Lat
a te
ter
r (B
(Blu
lue
e Drrag
agon
onfl
fly
y Lt
Ltd.
d)
A ca
cata
talo
logu
guee reeco
cord
rd for thi
hiss ti
titl
tle
e is a
ava
aililab
a able
le
frrom the Bri
r ti
t sh L
Lib
ibra
rary
ry.
ISBN: 97
ISBN 9788 0 75
7502
02 9921
21660
eBoo
eB ook
k IS
ISBN
BN:: 97
9788 0 75
7502
02 921
921777
Dewe
De weyy nu
numb
mberer: 00
005.
5 1-
1-dc
dc23
23
Prin
Pr inte
ted
d in C
Chi
hina
na
W yl
Wa y an
and,
d, p
par
artt of Hac
ache
hett
tte
e Ch
Chilildr
d en
en’s Gr
Grou
oup
p
and
an d pu
publ
blis
ishe
hed
d by Hod odde
derr an
and
d StStou
ough
ghhto
ton
n Li
Limi
m te
ted
d
www.
ww w.ha
hach
chet
ette
e.c
.co.
o uk
All im
A imagages
es cou
ourtrtes
esyy of Shuhutt
tter
erststoc
ock k ex
excece
eptpt:: p5 (to
top
p leleft)) Da
Dailily
y Hera
rald
ld AArc
rchihive
ve/N
/Nat
atio
iona
nall
Medi
Me diaa Mu
Museseum
um/S /Sci
c en
encece & Sococieiety
ty PPic
ictu
turrre Lib
ibra
rary
ry; p5 ((bo bott
ttom
om rrig
ig
ght
ht)) Sc
Scie
ienc
ncee Mu
Muse eum
um//
Scie
S
Sc ienc
ie ncee & SoSoci
ciet
iet
ety
ty Piict
ctur
ure
e Li
L br
brarary;
y; pp12
122 ((bo
bott
bottom
ttom
om lef
eft)
t)) W
Wikikimed
ikim edia
ia Com
ommo monsns/V
/Val
a ia
iant
n
Tech
Te chnonolo
logy
gy Ltdtd.;; p
p133 (to
top
p le
left
ft)) Va
Valilan
antt Teechchnonolo
logy
gy Ltd td.;; p
p14
14–1
–155 Scra
ratc
tch
h (S
(Scr
crat
a ch is a
proj
projec
ectt of tthe
he Lif
ifel
elon
ongg Ki
K nd
nder
ergagartrten
en G Groro
oup at ththee MI
MIT T Me
Medi diaa La
Labb); p1
p19 9 (t
(top
op) Liigh
ghtb
tbot
ot Inc
nc.;.
p28
p2 8 (b
(bot
otto
tomm ri
righ
ght)) IISt
Stoc
ockpkpho
hoto o/EEd StS oc
ock k.
k.
While
Whil e ev
ever
eryy at
atte
tempmptt ha
has bebeen
en mad
adee to cle
learar c
cop
opyr
yrig
ight
ht, sh
shou
ould
d there be an
any
y in
nad
adve
vertten
entt
omisssi
om sion
on thi
hiss wi
willll b
be
e re
rect
ctif
i ie
ied
d in
i fut
u ur
uree edittio
ions
ns.
Discla
Disc laim
imer e : Th
Thee we
webs
bsitite
e ad
addr
dres
esse sess (U
URL
RLs)
s) inc
nclu
lude
ded
d in
n thi
hiss bo
book
ok werere va valilid
d at
a the
time
ti me of go
goin
ingg to preress
ss.. Ho
Howewevever,
r, b bec
eccau
a se of ththee na
natu
ture
re of thhe Innte
tern
rnet
et,, it
i is po
p ss ssib
iblee
that
th at som
ome e ad
addr dres
esse
sess ma
may y ha
have
ve c cha
hang ng
ged
ed,, or
o siti es
e may h hav
ave e chan
changegedd orr clo ose
s d do downwn
s nc
si nce pu
publ
blic
icat
atio
on.
n WWhi
hilee the aututho
horr an nd pu
publ
blis
ishe
herr re
regr
gret
et a
any
nyy inc
ncon
onveveni
nien
encec thi
ce h s ma
may y
caus
ca use
e th
the
e re
readaderers,
s, n
noo re
resp
spononsi
sibi
bilility
ty for any sucuch h ch
chan
ange
gess ca an be acc cep
epte ted
d by eit ithe
herr
the
th e au
auth
thor
or oorr th
the
e pu
publ
blis
ishe
her.
r
Note tto
Note o re
read
aderer: Wo
Word rdss hi
high
ghliligh
ghte
ted
d in b
bol
old
d ap
appe
pear
ar iin
n th
the
e Glos
Glo sa
sary
y on pa
page
ge 30.
Answ
An swer
erss to act
ctiv
ivit
itie
iess ar
aree on ppag
age e 31
31.
Contents
4 Codding your World
6 Alg
gorithms in Action
8 Onees and Zeros
10 Min
nd your Language
12 Lan
nguages for Learning
14 Scra
atch!
16 Acc
curate Algorithms
18 Gett in Step
20 Deccisions, Decisions
22 Go with the Flow
24 Goiing Loopy
26 A Buug’s Life
28 Codding Careers
30 Glo
ossary
31 Furt
Further
ther Resources
32 Index
Co d i n g HELP!
H
your
Wo rl d ?
Computters are everywhere. Helping ha
ands
Whenev ver you heat food
in a micrrowave, watch an Althou ugh computters may seem m veryy
animated movie or play with powerrful, thhey neeed people too lend
da
a smartpphone, you are using hand. Computers can’t act on n their
compute er technology. But all own and allways need a seriess of
hnology won’t work
this tech in
nsttruc
ctions to tell them wh
hat to
o do.
unless yyou
ou tell it what to do
do. These instructions are calleed program ms.
Writingg programs is called coding
and is c
an carried ouut by peop
ple known
as cod ders, or programmers.
d
IT S
IT’S
With a program installed, comp puterss’
YOUR
biig bra
ains ca
a an ru
un sup
per-sm
mart code e
TURN
to do aamazing things. For exam mple,
in 19977, IBM
7 M’s Deep Blue comp puter
runningg a chess-playing progra am be eat
the Wo orld Champ
o pion chesss pla
ayer,
Garry KKasparov. Result!
4
I thinnk there
is a world be
may
market for uters.
ve comp
fiiv
TRUE STORY
Computers Galore
7KRPDV:DW WVRQ
ZKRZDDVRQFHFKDDLUUP
PDDQ
Q R
RII, %0
PDGGHWWKLVSUHGLF
FWLRQLQ
ZKHQ
QFRPSXWHUVVZHUHºUVW
LQYHQWHG+RZZ
M 14 10 co m pu te r in use at the 7KHU
ZURQJKHZD
UHDUHQRZRYHU DV
IB
d M ot or C om pa ny in 1969. PLOOOLRQFRPSXWWHUVLQWKH
For ZRUOOG
GDQG
G PLOOL
H
LRQVPRUH
smarrtphonesDQ
QGWDEOHWV
ER
COMPUT
Hero!
7KHZRUOG±Vº
ºUVW
ºUVW
WFRPSXW
F WHHU
SURJUDPPHUZ
SURJUDPPHUZDVD 9LF
FWRULDQZZRPDQ
FDOOHG$GD&RXQW WHVVRI/RYYHHODFH
+HUIULHQG&KDUOHV V%DEEDJHWWUULHGWR
EXLOGWKHºUVWFRP PSXW
WHUV,QQ
$GDZURWHDVHULHV VRI
ILQVWUXXF
FWLRQV
WRGRVRPHFRPSOOLFDWHGPDWWKKVRQ
%DEEDJH±VPDFKLQQHVLIWKH\\ZHUH
FRPSOHWHG$GDKDGZULWW
L WHHQ
WKHºUVWFRPSXWHUSURJUDDPP
Ada, Countess of Lovelace
5
r i t h m s
Algo i o n Sh
hare the sweets!
in Ac t Yo
You also
l use algorithms
l ith tto solve
l
prroblems. Say you’ve been given
ab big bag of sweets, but have to
share them equally. You need to finnd
a way to share the sweets out. Herre
A comp
All puter programs rely are two algorithms for doing this:
on algorrithms. These are sets
of step-b
by-step instructions to
performm tasks or solve problem ms.
Coders use algorithms to help
them plaan out their programs. Sweet Sh haring:
1
Algorit m n e
e in a circle
g e eve ryo
1. Arran
weet to
ne sw
2. Hand out o rn u
in tu
each person weet,
Ever
E veryday
ryday
y algoritthms h e n e v e ry one has a sw
3. W 2
iive y o u rs e lf one
g
You use algorithms all the time, pro
obably e p e a t st e p s 2–3 until all
4. R
re gone
without even knowing it. Recipes foor the sweets a
making different foods and drinks aare
types of algorithm. For example, wwhen
you make a glass of squash, you kn now to
open the squash bottle, pour the ssquash
into a glass and then add water. Thhe
algorithm for this task might be written
n as:
a
as Sweet Shari
Alggorithm 2ng:
1. Count all t
he sweets
2. Count how
ttle top
1. Remove squash bo th
here are
many people
s
2. Pour squash into glas 3. Divvid
de number o
f sw
weets
3. Turn on tap by number o
f people e
ter 4. Givve each pers
4. Fill glass up with wa same numb
on thhe
off tap er of sweets
5. When glass full, turn as thhe answer
6. Drink!
Diffferent method
ds,, ickla l yer:
same target Robot Bhrm 1
Algorit ne up
o to b ri cks and pick o
1. G
Just like the sweet-sharing algorithms, all
2. Return to w
there are many computer algorithms on wall
3. Place brick o
that can do the same job. Programme ers ps 1–3 until n
4. Repeat ste
spend lots of time thinking through theeir
bricks left
algorithms, trying to come up with the e
fastest or most efficient way to perform
m
a task.
Write Instr
t uctions My
for a Recip
Can you an
making a m
make the re
d a friend ea
eal that you
b
e
ch write an a
oth like? Use
lgorithm for
lots of steps
Recipes
cipe really c to
o
lear. Compa
re your result
s:
Did your frie
nd come up
you didn’t th with someth
ink of? ing that
n e
O ross and with electrical circuits. These
carry tiny pulses of elec
that act like a code, send
ctricity
ding
Ze data
d ata as streams of just tw
numbers – 1 and 0.
n
wo
Number systems
You use the decimal, or base 10, number Binary iss another number system. It uses
system every day when you are counting only two o numbers – 1 and 0. When you
or doing sums. The decimal system want to go higher than 1 in a column, you
contains 10 different digits (0, 1, 2, 3, 4, 5, put a 1 in the next column on the left and
6, 7, 8 and 9). When you want to count then sta art counting from 0 again in the
higher, you add an extra column on the first colu
umn on the right. Below is a table
left and continue counting – 10, 11, 12. showing g the binary numbers up to 15.
DECIMAL 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
BINARY 0 1 10 11 100 101 110 111 1000 1001 1010 1011 1100
1101 1110 1111
STRETCH F
YOURSEL 17
Chan ge De cim al to Binary en see if you can work out
9, th
16
od on page
he meth binary? ht) are in
Look at th cim a l numbers (rig
re e d e
what these th
21
.
u m b e r 1 5 a s an example
done n imal
r 1111 is dec
n page 31
n u m b e
So, binary
1 = 1 5 number 15
.
16 8 4 2 ach
u can use e
Answers o
1 b e r y o
1 1 1 Reme m
ly once!
8 number on
Have a look at thes
e examples:
C l
Column calculation
l l ti ns Convert binary
y numbe
er 101 to a decim
c al numb
beerr::
Binary can be turned into Columns
decimal numbers, and vice versa. Decimal 16 8 4 2 1 HELPFUL TIP::
The binary numberrs
You just need to remember that Binary
1 0 1 show which decimaal
values to add
each column of a binary numbe er together!
=4+1=5
is worth twice as much as the
previous column. So, the first five Add together the de
d cim
i all numb
bers that h
have a 1
columns of binary numbers equa al beneath them.
1, 2, 4, 8 and 16 if they are written
n So, binary number 1 0
1 equals decimal numbe
as decimal numbers. The first r5
column is always on the right, Convert binary numbe
r 10010 to a decimal nu
and you add new ones on mber:
the left. Columns
Decimal 16 8 4 2 1
If you write a binary number Binary 1 0 0 1 0
underneath the columns of
decimal values, you can work = 16 + 2 = 18
out the value of the binary Add together the decim
number. All you need to do is al numbers tth
haatt have
a 1 beneath them.
add together the decimal So, binary number 1 0
0 1 0 equals decimal
numbers that have a number 18
1 beneath them.
STRETCH
YOURSELF
Bec
Be co
omme
e a Binary Spy! Here are some examp
Make a secret number system ple
les:
on your
left hand by using washable ink
to + -/
/
"#"$
% "
" ; < = ->
; >
16
6 on your thumb.
Answers on page 31
@
@
You now have a binary code
Y
-$'%A$A#*
-
& '
*
sticking up equals a binary 1. Ca B E
n you
tell a friend (without speaking) you need to hold up to make
what 6, 10, 13
number you are thinking of just and 20?
by
using your hand?
Early computers were
programmed d using
i long
l
Min age
These took ages to key
in
n and also to check if a
Compute
ter talk
t lk
10 Print ‘He
llo Mum’
Hello Mum Printmeans displa
y on
the comput
Hello Mum er’s screen.
20 GOTO 10
Hello Mum GOTO is a BA
SIC
Mum command tto
Hello to a differen
o jump
t line
number.
JAVA
This is ussed to write
e small games and
programs for smartphones, table ets an
nd
computers. Java is also used d for makking
animate ed cartoonsns on webb pagges.
C+++
This advanced d and very
powerful language has bee en
SQ
SQL
QL used to write many famous
Thiss lang
g ua
age was developed by IBM M commputer program ms. These
and d is used to create databases. A incllude Microsoft Office and d
dattaba ase is an applica
ation that stores bro
owser prog gramss such as
largge amounts of information in an Google Chrome and Apple
orgganised way, so that you can find Saffari that arre used forr
it again easily. viewing web pages.
pages
11
Every programming
language has its own
STRETCH
YOURSELF
S aki
Spea king LOGO!!
Control the Turtle
The LOGO language use
The LOGO language was s simple commands
to make the turtle draw
different shapes.
inveented d by an American Try using LOGO to work ou
t the answers
scientist called Seymour Papert to these questions:
in 1967. It let children program
a little robot called a turtle to Which one of the follow
W
ing shapes
mov ve aroound the floor. Typing w uld this LOGO progra
wo
m draw?
a command such as Forward
20 steps would make th he robot Forward 100 steps a b
move forward 20 steps, whilst Left 120 degrees
Forward 100 steps
typiing Left 180 degrees wou uld
Left 120 degrees
make it turn round 180 degrees c d
Forward 100 steps
(half a circle)). Some turtle robotss
carried a pen so you could TThis LOGO program makes the
turtle draw a
proogram them to draw on paper. +
to make it draw a square instea
d?
120 steeps
Forward
deg es
r e
Right 90 s
100 step
Forward
Answers on page 31
deg r e es
Right 90 s
r d 120 step
Forwa re e s
deg
Right 90 s
a r d 100 step
Forw
12
Othe
er fun langaua
langauages
ages
STRETCH
YOURSELF
ch Challenge
Robot Rocket Laun
I
e robot has to make
eight movements th
rocket. Can you
to follow a path to his
g nine commands
work out the remainin
h his rocket?
he must follow to reac
forrw
5. Move fo
5 war
ardd 1 space
forrwwar
ard d 1 space
Answers on pa
1. Move fo
1 n to the tleft
ef
to the r igh
ig htt 6 Tur
6. urn
2 Tur
2. n
urn war
forrward d 2 spaces
for
fo w
rw ard
ar d 1 space 7. Move fo
3. M
Moov
ove
to th
the left 8. Turn to the t
8 e
lef
4. Turn
age 31
13
Scratch is one of the
cr
schools. Scratch lets you
u
Sprite
e right
forever
set x to
i t
0
set y to 0
Scripts are
rea
if on edge, bounce move
mov 110
0 step
st
direction
Scratch sc
creen
Sc
cratch the Cat
A Scratch
S screen has three main n parts:
the
e palette, scripts area and stage. The
paalette stores all the Scratch insttructions
(caalled blocks) that you can use e. You
caan pick and move the blocks from
the
e palette to the scripts area, wwhere
yo
ou snap the blocks together to build
a script
s to create your program. Your
Sc
cratch program is then displaye ed on
the
e stage.
14
Sc
cratch
t h bllocks
k TRUE STORY
M
Many types
t off block
bl k are usedd in Scratch.
S
These are all colour-coded. You snnap A Big Hit 7
KRX
together the different blocks to build
b ild YLVLWWKH VDQGVRISHRSOH
R
a program. Below are the ones you’ll ZHEVLWH¬ ҬLFLDO6FUDWFK
VFUDWFKPL
HYHU\GD\ WHGX¬
probably
p robably use th
the most: %
ºYHPLOOLR \-XQHRYHU
QSUR
FUHDWHGRQ MHFWVKDGEHHQ
WKHZHEVL
WH
MOVE 10 STEPS
Motion
Motion
Blo
ocks like these make the sprites move
accross the stage and change diirection. STRETCH
YOURSELF
PLAY SOUND MEOW
Expl
E p ore Scratch!
Look at this Scratch
program of a
Sounds DJ cat mixing sounds
. You can add
These blocks play sounds. You ca
an pick a to these sounds by pr
essing some of
sound, such as a drum or cat’s m
meow, or the keys on your keyb
oard. Just type
this address into a w
record and add your own. eb browser:
http://tinyurl.com/watchdjcat
WAIT 3 SECS
A l go r needs to be instructed
very carefully. This can
ttake lots and lots of steps.
Be
B e precis
pr
recise
se Here
e e iss a
another
o e example
e a p e of
o an
a aalgorithm,
go ,
this time for brushing
gyyour teeth:
People have to be very acc curate
when creating algorithms. M Missing
issing out 1. Turn on ta
ap
important steps or getting one wrong 2. Squeeze toothpaste tube
can mean the program doe esn’t work. 3. Use brush to clean teeth
For example, an algorithm fo or a robot 4. Put cap on toothpaste
to walk forwards needs to contain
steps that tell the robot to sttop if it The algorithmm does
doesn’t
sn t say what
whhat sort oof
reaches a cliff edge. Othe
Otherw
e wise, it will brush to use, to takee the cap off the ttube
continue
ue walkin
walkingng and fall offf! before squeezing it,, or to turn off the
tap. Oops! What ste eps could you add d to
make
m ake this algoritthm
thm w
work bett
better?
TRUE STORY
DQHZ
$1 Miillion Lost ,Q \ RLO
REX\ O
SX
S WH
XW HUUSURJUDPW WR
FRPS S DQ\ ZD V
PS
IRUUDQ$PHULFDQFR RU LW P
KP
DOJ
VZLWFKFKHGRQ%XWWKH
QROLPLWRQKRZ ZPDQ\
KD G
DG
DN H¬DQG
G UVLWFRXOGP
RUGH HUWV
PD
P GH
DG WK
HW RX
KR V
XV QG
DQ
VD V([SH
GV
VRLLWP
RVW YHU
RY
L NWKHFRPSDQ\O WKDQ
WKLQ Q
V
PLOOLRQLQOHV
ºYHVHFRQGV
16
STRETCH
YOURSELF
A-Maze-ing Algorit
hms Now, ask yourself thes
Build a maze with bo e questions:
xes and cushions.
==
movements you wou
ld have to make
to travel through the d d you have to mak
di
maze without e any changes?
bumping into any of
the obstacles.
D you need to add
Do
extra steps and
Blindfold a friend or commands to your al
c
parent and read gorithm?
out the commands
in order and one
at a time. They have How many runs of yo
H
to do exactly ur algorithm did
what you command. y u need before it w
yo
orked perfectly?
An aans
nswer
swer
f everything
for thi
17
The steps in an algorithm have
in
Get
to be not only precise, bu ut also
in the right order. If you get the
1. @ -/
Jumping around 2. Player shooots
3.
Keeping track of the steps inn an 4. If a goal wasn’t scored, go to liine 2
algorithm can become more e 5. If a goal was scored, addd one to Score
and g go to
o line 1
complicated if it is designed to jump
back to an earlier point. This simple
algorithm (right) keeps trackk of a This algorithm almost works,
work ks butt every
footballer taking shots at a g
goal. But time line 5 adds one to the score, it jumps
the score isn’t going up each time back to line 1, which sets the score to
he scores. Can you work outt what is zero again! The solution is simple: line 5
wrong with the algorithm? should end with ‘go to line 2’.
STRETCH
YOURSELF g
plug
1. Put in bath p
5 Wash
5.
g
plug
6. Take out bath p
Answers on page 31
Get out of th
7. G
7 b th
he ba
8. Get undressed
8
18
STRETCH
YOURSELF
You
ou can visit Lightbot by typ
ping this
address into a we eb browser: http://tinyurl.com/light-robo
t-game
Subroutin
nes
If…
f Th
Then
n
M
Many programs askk a computer t toto make car-racing game below, the game’s
decisions based on the information n that code has to make lots of different
they receive using an IF statementt. This decisions. Then, when the program for
states that IF something is true, THEN the the race decides that the game should
program will respond and do some ething. end, it runs a particular piece of code to
give the player a final score and printss
In computer programs, decisions a l i
are ‘Game Over’ on the computer screen n.
made all the time. For example, in the This is called code selection.
If the carr ru
uns out of fuel,
then
n gam me over
If the p
playe
y r’s ca
c r is in first place,
the en disp
play message
If the player presses the brakess, ‘You’
u re in
n the lead!’
l
then slow the car down
20
More
r or
r less Sortt it ou
ut
ut Keep Trying’
Print ‘Good Bu
Yes No
and End Program
Does it Does it have
have legs? a handle?
No Yes No Yes
Challenge:
Answers on page 31
e start or end
of a whole program
or just part of
a program.
Follo
ow the
flow chart
Decision
?
Many coders use a diagram m called a Diamond sh hapes show where a
flow chart to map out their a
algorithm program makes a de
cision. This is
or program. This helps them tto find usually a simple deci
sion such as
errors and make improveme ents. ‘yes’ or ‘no’ or ‘true’
or ‘false’.
Lamp
Start doesn’t work
Bulb
burned o
ut?
No
Lamp
Throw dice plugged in?
Yes
Yes
Move the
counter Replace bulb
No
lamp
Yes Repair Plug in
lamp
Slide
Landed on down
snake head? the snake
Answers on page 31
No
COMPUT
E R
Yess Hero!
At Climb
bottom up
of
ladder
ladder? Frank Bunk
er
DQHQJLQHH Gilbreth ZDV
U
PDNLQJMRE ZKRHQMR\HG
V
No DVSRVVLEO DVVLPSOH
H
)UDQNLQWU ,Q
ºUVW»RZF RGXFHGWKH
End RXWZRUNHU KDUWVWRPDS
FKDUWVZRX V±MREV)ORZ
OG
SRSXODUZL ODWHUEHFRPH
WKFR
SURJUDPPHU PSXWHU
V
Go i n g Loop
Turn round
Shout: “I’m feeling dizzy”
Lo o p y The
Loop
24
In a loop
p
Ten Items Or Fewer
S
Some loops
l continue
ti for
f as
B-/
long as the program runs.
These are called infinity
N is a variable. It equals the
loops. Other loops, like the number of items scanned. It is set
countdown loop on to
zero to start with because nothing
page 24, are told to repeat has been scanned.
a set number of times.
Loop
Scan item
Conditional loops are another _ " B
-BA
type of loop. They keep
repeating the steps in the One is added to the
loop until something else number of items scanned.
happens. For example, this
algorithm for a shop checkout If N > 10, ring bell and display
scanner only allows 10 items ‘No more than 10 items!’
or fewer to be scanned. If and Leave Loop
more are attempted,
tt t d th
then th
the Loop Again
scanning loop ends.
STRETCH
YOURSELF
Minutes-/ Z
Fix the Time
Here is a loop that is rs - / [
k H ou
part of a digital cloc
program. It’s not wor
king
Lo op Z -Z A
sh ow s
properly because it A
[ -[
the time 02:07 as 01 :67 . \Z ->/""I
hich
Can you work out w /
of the three numbere
d
\ [ -#$"I [ -
lines below should
line
replace the circled
th e prog ra m \Z ->/"I
to get A
-[
working properly? Z -/[
#\Z ->/"I
Z -[
]\Z ->^"I
31
Answers on page
Only some programs
Chec
ck and test
26
Catch the B
C Bug
IK
program for playing ‘Tag’ or ‘It’
. But one
of the arrows is in the wrong pla
ce for
the program to work properly.
Start
Launch fa
ailure
S
Some bugs
b iin programs can
be devastating. A bug in th he
Choose
guidance computer of an one
person
Ariane 5 space rocket mad de to be the
the rocket veer off target a and chaser
finally self-destruct just a miinute
nute
after
ft lift-off in 1996. Are Yes
you the Chase
chaser? the other
children
N
No
TRUE STORY
No
Have
Run away from you caught
the chaser someone?
G
Moth Bugss,QDGHD
PRWKFDXXVHGDVZLWFKWR Yes
H WKKH
PDOIXQFWLRQLQVLG QH
No
RQ
+DUYDUG0DUN,,¬ V
Has
XWHUV
RIWKHºUVWFRPS FN
the chaser
You are not
URJUDPPHUVVW WXF caught
7KHSU you?
the chaser
WK H
WKHPRWKLQWR anymore
OR JE
RJ ERRN,W WZDV
FRPSXWHU±VO J±
±V
J± º
V °EXJ
ºUVW°
FRPSXWLQJ
Answer on
o page 31
Coding Think you might become a
whizz at computer coding
Work
king toge
ether
r
ER
In tthe
he past
past, computer programs and
a COMPUT
code were often written by only
y one Hero!
person. Today, many major appliccations
and games need dozens or even n
hundreds of people to build themm. y Z
Jack Dorsey
ey ZDV
DV
IDVFLQD
ID
DVFLQDWHGE\FR RGLQJ
DV
VDFKLOG,Q
Some people work out what the 'RUVVH\DQGKLVEX
XVLQHVV
program should do, while others write SDDUWQHU%L]6W
WRQH
and test the code. Many other co oders ZUR
RWHWKHºUVWYHHUVLRQ
RIWKH7ZLWWHUVRFLDO
RI WKH 7ZLWWHU VRFLDO
V
work on existing programs, writing
g QHWZRUNLQJDSSLQMXVW
code for new features or debugging
gging WZRZHHNV2YHU
problems with the latest programm. PLOOLRQ°WZHHWV±DUH
QRZVHQWHYHU\GD\
Jack Dor
28 sey
Young g co
oders –
Think big
g just like you!
TRUE STORY
PH
r ld W i d e Fun7KHJD
Wo Q
FUHDWHGL
7HWULVZDV HQJLQHHUFDOOHG
WHU
E\DFRPSX WQRYD7HWULVKDV
M L
$OH[H\3D UH
WR
SURJUDPPHG
H E HH Q V
VLQF RIFRPSXWHU
R Q O RW V
ZRUN WDEOHWV
SKRQHVDQG
STRETCH
YOURSELF
ese questionss:
Write a Then, ask yourself th
Computer rate?
ram operra
How would the prog
Program
Can you think
of a computer
tto know?
program that
would make
your life easier?
to use it?
Try to sketch
t
out all of its
in advance?
different parts.
s a r y
G los database A program
that allows people to
parallelogram A shape
with opposite sides that
are parallel and also
store huge amounts of
equal in length.
l orithm A set of steps
alg information on computers
that are followed in order with ease.
programmer A person who
to solve a problem or writes computer code and
debugging To identify
perform a task. programs, either for fun or
and remove errors in a
as a job.
beta tester A person computer program.
who tests a computer smartphone Powerful
program that is almost decimal Also known as
mobile phone that
base 10, decimal is the
finished to try and find contains a mini computer
any bugs or problems. number system that you
which allows users to view
use every day. It contains
videos, listen to music
binary Also known as the digits, 0, 1, 2, 3, 4, 5, 6, 7,
and run lots of different
base 2, binary is a number 8 and 9.
programs.
system that contains just
two digits: 1 and 0. decomposing Breaking
string A type of variable
down a complicated
(see below) that stores
browser A type of task into smaller parts
one or more letters or
computer program used by or steps, making it easier
other characters.
people to view websites on to understand and
the World Wide Web. write code.
subroutine A section of a
program which performs
coding Writing the lines of flow chart A type of
a task and can be jumped
code in a program that diagram that maps out the
back to as many times as
make a computer or other actions and decisions that
the whole program needs.
device work. occur within a program
or part of a program.
variable A location for
code selection When a storing information in a
program is told to run a input Data or commands
program which can be
particular piece of code that a user enters into
changed by other parts
after making a decision, a computer using a
of the program.
such as running the code keyboard or by pressing
that says ‘Game Over’ and a touchscreen on a tablet.
giving a final score when
the program decides the loop A part of a computer
game has ended. program that repeats the
same steps and instructions
compiler A computer over and over again.
program that converts Many loops are conditional
instructions written in – they continue until a
a programming language condition is met or an
into code that a computer order instructs them to stop.
can understand and
act on. output The results of a
computer’s processing
and work. Output is often
displayed on a screen.
30
u r t h er s Answers
F o u rc e
Res
page
pag e 18 8
page
pag e8
mal to Can
Ca n YoYou F x th
u Fi the e
nge
ang eD ecim
Dec
Books Cha
Ch
stru
Inst
In u ns?
ions
ctio
ct ? :
Bina
Bi y
narry:
How Things Work: Electrical Gadgets 1. P
Putut in ba batthh plu g
lug
00
000
6 = 100
16 0
by Ade Deane-Pratt (Wayland, 2013) 3. FFilil ba
bat h
th w i
it h wat
wa er
ter
0001
7 = 100
17 01
8. GGet et ndre
und
u ress ed
ssed
21 = 1 010
101 1
01
Quick Expert’s Guide: Computing and Programming 4. G
Get nto
et iint o th
the batth
e ba h
by Shahneila Saeed (Wayland, 2015) e9 5. W
Wa s
ashh
page
pag
!:
y!: 7. G
Get et out of th the batth
e ba h
Bec
Be ome
com e a Bin ary
inar y Sp
Spy
d ake
6. TTak e out
ou bat
ba h
th plu
p u g
Quick Expert’s Guide: Creating an App 6 = Yo
You ur r mid
m d d
dl e and
an
ngeger 2 G
2. Get dre esssed
by Chris Martin (Wayland, 2014) our
fo th fin
urth
10 = Y Youour inr dexx an
inde andd
rth h fi nge
fing err page
pag e 21
ourt
ffou
Technology Timelines: Digital Technology ourr in dexx,, m
inde mid de
ddl Spe
Sp elliling estt
ng Tes
13 = YYou
by Tom Jackson (Franklin Watts, 2015) r Cod
Co de e C alllen
ha eng e
ge:
and
an d lil ttle
tt e fin
f ger
inge
* The
The c
sc ores
ore s 4 , ,6
5, 6, 7 an
andd
20 = You our th umb
thum b an
and d
r 8 wo
wou l
uld ear
ea rnn a
mid
mi dle
ddle f in ger
inge
‘Go
‘G oodod Bu Butt Ke
Kee ep p Tryyin g’
ing’
Websites .
page
pag e 12 mark rk.
https://www.commonsensemedia.org/lists/coding-apps-
Con
Co trol th
ntro e Tu
the Turt e:
rtle
and-websites e scsco ress 9 a
ore nd 10
and
* The
The LOG
LO GOO p rog
ro ram
gra m * Th
The
A great page containing links to lots of different computer wou
wo u l d ear
ea n
rn a ‘Bril
Br t!’’
a t!
illilian
wou
wo ld
uld dra
dr aww the
t he
activities and languages to help you learn about coding. ral tr ngle
iang
tria le markrk. .
equ
eq ate
uila tera
(an
(a swer
nsw e d)
https://www.helpkidscode.com/ page
pag e2 3
23
h
fth the ow Cha
F x th
Fi e Flow
Fl t:
harrt:
A website for parents, teachers and older children. * ThThe rstt an
e fifirs andd fifift
oth
bot
b h say
sa y * ‘P u
Plu g in am
lam p’
ness
liline s
sh ould
ou ld
s . sho
sh uld go in the
ould the bbluluee
http://learn.code.org/hoc/1 ‘ or
‘F war
orw a d
rd 1 00 s tep
te ps’.
rec
re t
cta n
ang u
gula r
lar sha
sh p
ape e. .
A video tutorial which helps you use the Blockly coding
page
pag e 13
language to create a simple program. * ‘B burrned out
u b bu
‘Bul ut?’
Rob
Ro ot Ro
bot Roc kett
cke
e sho
sh u
ouldd go in he
the
t een
gre
Lau
La n
unc h
ch C hall
ha eng
en ge:
http://www.light-bot.com/hocflash.html t o
of d am
di ond
on d sha
sh apep .
e.
e
Herre
He a re t he
the rest
es
Have fun programming an on-screen robot called Lightbot. e co
the
th com mmm and
an s
ds t he
w ll neeeed n ord
d in rder page
pag e2 5
25
rob
ro ot wi
bot
is
his
h rock
oc e
ket.t Fix
Fi the me:
x th e Tim
Ti e:
http://www.scratch.mit.edu to rea
eacchh
ne
Line
Li umb
num
n er 2 sh
ber sho uld
ould
Learn more about coding by creating programs starring e circ
ci led
rcle d ne.
liline
e fo rwa
forw ard rep
re p lace
ac e the
th
Scratch the Cat and other fun characters. 9 Mov
9. ove
1s pac
pa cee
rn ttoo th
the ghtt
e riigh page
pag e2 27 7
10.. Tu
10 Turn
http://www.wordfreegames.com/game/binary-game.html a
war d
rd Cattch e Bu
Ca c h the
th Bug g::
11. Mo
11 Mov vee for
forw
A groovy game to help teach you how to use The
Th e arro
ar o w at the e bot o to
tom
1s pac
pa ce e
ght
righ t o
of the c har
ha t
rt is in
binary numbers. 12. Tu
12 rn to
Turn o ththe ghtt
e righ
a rd thhe wrwro ongng pl ace
plac e.. To
13.. Mo
13 Mov e
ve forw
or w
deb
de bugu g the
th e ogr
pro g am,
ram
pac
2 sspa es
ces
thhiss a rrow
rrow hou
sho uldl d poin
po intt
14 Turn o th
4. Tu rn t the ghtt
e riigh
om
from
fr Now
‘No w you
yo u are
ar e the
th e
15.. Mo
15 Mov vee f orw
for a
war d
rd
cha
ch aseser’r to ‘ Cha
Ch ase s e the
th e
pac
4 sspa cese s
e le eft oth
ot herer ch chilldr
dre n.
en’
16. Tu n tto
urn o ththe
7. Mo
17 Mov vee f o
for war
wa d
rd
1 pac
spa
s cee
n d ex
I r
e recipe algorithm 7
electrical circuits 8 robots
Bee-Bots 13
f Lego Mindstorms 13
a flow charts 30
algorithms 30 b t 19
Lightbo
in action 23 precise commands 16
everyday 6 debugging 27
precise instructions 16–17 ps 23
filling in gap
Roamers 13
ps 18–19
step Turtle 12
symbols 22
using different methods 7
s
g Scratch programs 13
b games 11, 13, 14, 28
Babbage, Charles 5 blocks 15
car-racing 20 screen 14
base 2 see binary Minecraft 29
BASIC language 10, 29 sprites 14
Snakes and Ladders 23 website 15
beta testers 26, 30 Tetris 29
binary 8, 9, 30 smartphones 4, 5, 11, 30
8 Gilbreth, Frank Bunker 23 SQL language 11
converting decimal to binary
con vert ing bina ry to dec imal 9 squash-drink algorithm 6
h steps in an algorithm
branching tree diagram 21 Hopper, Grace 11
browser 15, 19, 30 jumping around 18
programs 11 subroutines 19, 30
i Stone, Biz 28
bugs IF ... THEN statement 20
beta testers 26 strings 24, 30
infinity loops 25 subroutines 19, 30
check and test 26 inputs 22, 30
c t
uage 11 j tablets 5, 11, 29
C++ l ng
+ la ngu
Jalbum 29
code Java language 11
building 10 v
che f r bu
ecking fo g 26
ugs variables 24, 30
k
decisions 20 keyboards 30
huge projects 29 du program 13
Kod
w
writting programs 4 Watson, Thomas 5
code selection 20, 30 web pagges 11
l World Wide Web 30
coders 4, 6, 10, 17, 19, 22, 28 LOGO language 12
coding 4, 10, 30 loops 30
careers 28–9 conditional 25
learning 12 countdown 24, 25
column calculations 9 infinity 25
commands 30 and variables 24
English language 10, 11 Lovelace, Ada, Countess of 5
robot 13
compiler 10, 11, 30 m
computer mouse 22 mobile phones 29, 30
computers moth bugs 27
and Charles Babbage 5
decision-making 20–21 n
early 10, 27 number systems 8
electrical circuits in 8
instructions for 4, 16 o
personal 13 outputs 22, 30
repeating tasks 24
conditional loops 25 p
countdown loops 24, 25 Pajitnova, Alexey 29
Papert, Seymour 12
d Persson, Markus ’Notch’ 29
data 8, 21, 22, 24, 30 programmers 4, 5, 7, 22, 23, 26,
27, 30
databases 11, 30 prog ram min g languag es 10–1 3
debugging 26, 28, 30 program s 4, 6
decimal 8–9, 30 8 beta testing 26
converting decimal to binary browser 11
vert g
ing bina ry to dec ima l 9
con the first 5
decisions 20–21 Python program 13
decomposing 17, 30
Dorsey, Jack 28
32
Plenty of Books to
INFORM AND ENTERTAIN
S FOLLOW US ON
ON’T MISST
D LATE www.facebook.com/waylandbooks
THE WS!
NE www.twitter.com/waylandbooks