2. “Everybody should learn how to program a
computer because it teaches you how to think.”
- Steve Jobs
3. Six Reasons a Non-Computer Nerd
Might Want to Learn to Code
1. It's like learning to read or write
2. It's useful, even outside of computer geek
circles
3. It's helps you talk to actual programmers
4. It's actually a fun hobby
5. Computers are a part of society
6. It teaches other skills
4. A coder is going to the grocery store and his
partner asks him, “Would you buy a bottle of
milk, and if there are eggs, buy a dozen.”
What would you bring home?
What do you think the coder brought home?
SCENARIO #1
5. Upon arrival, his partner angrily asks him, "Why
did you get 12 bottles of milk?" The programmer
says, "There were eggs!"
This is an example of why we don’t program computers with
plain spoken language – we need to formalise the instructions
we give to computers
SCENARIO #1
6. SCENARIO #2
1 + 2 x 3 + 4
The answer is 11. Mathematics is a much stricter
“language” than spoken English. There are rules
about how things happen. In that way, coding is
a lot of maths.
7. SCENARIO #3
How do you make toast?
‘How do you make toast?’ is an interview question for software
developers, because it reveals whether you think computationally.
The ideal answer is a couple of steps away from something a robot
could understand. For a robot, clarity and precision are everything.
“Take four steps forward, open packet of bread, remove one slice
of bread”, for example, is a better start than “put bread in toaster”.
8. WHAT ARE ALGORITHMS?
• An algorithm is basically a set of step by step
instructions
• Before writing any code, you need to start with an
algorithm
• We need to determine what we're trying to achieve,
and then break down the problem into step by step
instructions.
• Once we have an algorithm, we can write code to
make a program
9. THE RULES FOR ALGORITHMS
• precisely states a set of instructions
• the procedure always finishes
• and it can be proven that it works in all cases
10. HOW TO SOLVE A PROBLEM
• When you use your brain to take a big problem and break it
down into smaller problems, you’re using your brain to
decompose the big problem.
• Once we’ve decomposed the big problem into several smaller
problems, we can go onto our next trick, which is called
pattern match. This is when we look for similarities.
• Once I find the things that are the same, I can figure out what
things are different. And when I remove those differences,
that’s called abstraction.
• And after I’ve figured out the steps to solving a problem, I can
put those steps in a specific order called an algorithm, so that
anyone can use my directions to solve that problem.
11. THE CHILLI GAME
• Put 13 Chocolates in a bowl
• Put 1 Chilli in a bowl
• Whoever brought the chocolates goes first
• You can take 1, 2 or 3 chocolates at a time
• The aim is not to be left with the chilli
Instructions
12. THE CHILLI GAME
• 13 chocolates divides into three groups of 4, with
one left over
• I take one in the first round, leaving 12
• Then I take 4 minus whatever you took in the
subsequent round,
• This algorithm ensures that the other player is always
left with the chilli
How the algorithm works:
13. THE CHILLI GAME - ALGORITHM
• I take 1 chocolate
• You take 1, 2 or 3 chocolates (x1)
• I take (4 - x1)
• You take 1, 2 or 3 chocolates (x2)
• I take (4 - x2)
• You take 1, 2 or 3 chocolates (x3)
• I take (4 - x3)
• You take the chilli
14. HERE’S ANOTHER MATHS PROBLEM
Add all the numbers from 1 to 200 in your head.
You’ve got 30 seconds!
1 + 2 + 3 + ... + 198 + 199 + 200
1 + 200 = 201
2 + 199 = 201
3 + 198 = 201
201 x 100 = 20,100
15. MATH PROBLEM – ALGORITHM 1
• TOTAL = 0
• NUMBER = 0
• START
• Increase NUMBER by 1
• Add NUMBER to TOTAL
• If (NUMBER < 200) Go back to START
This algorithm is inefficient
16. MATH PROBLEM – ALGORITHM 2
• STARTNUM = 1
• ENDNUM = 200
• TOTAL = 0
• If (ENDNUM is odd) add ENDNUM to TOTAL
• If (ENDNUM is odd) subtract 1 from ENDNUM
• TOTAL = TOTAL +
(ENDNUM / 2) * (STARTNUM + ENDNUM)
This algorithm is efficient, because the number
of instructions don’t increase with the size of
ENDNUM
19. THE STABLE MARRIAGE ALGORITHM
In 2012, for the first time, a nobel prize was
awarded because of an algorithm.
The algorithm was concerned with college
admissions – how to match students to colleges
so that everyone got a place, but most
importantly, so that everyone was happy, even if
they didn’t get their first choice.
They called it The Stable Marriage Problem…
20.
21. This is an unstable marriage
Queen of Hearts would prefer King of Spades
King of Spades would prefer Queen of Hearts
+
+
22.
23.
24.
25.
26. THE STABLE MARRIAGE ALGORITHM
The Gale Shapley algorithm is now used all over the
world:
• In Denmark to match children to daycare places
• In Hungary to match students to schools
• In New York to allocate Rabbis to synagogues
• In China, Germany and Spain to match students to
university places
• In UK it’s lead to the development of a matching
algorithm for organ transplants
27. GOOGLE PAGERANK ALGORITHM
Not a search algorithm, but a ranking algorithm – ranks
all search results for your query so the #1 is the one
your most likely interested in.
PageRank looks at 2 things:
• The incoming links to a webpage, and
• How important those pages are
29. THE TRAVELLING SALESMAN PROBLEM
A travelling salesman travels door to door
through a number of towns and cities. The
problem – what’s the shortest route to take?
The answer to this problem is so important that
there is a $1 million reward for anyone who can
produce an efficient algorithm, or prove that
none exists…
30. THE TRAVELLING SALESMAN PROBLEM
Imagine you’re a travelling salesman, and you
need to visit a list of cities. The challenge is to
find the shortest route so you visit each city
once, before returning to your starting point.
You might imagine the best thing is to just
consider all the possible routes..? The method of
checking all the possibilities is a type of
algorithm, but is it efficient?
31. THE TRAVELLING SALESMAN PROBLEM
• For 3 cities, it works fine because there are
only 3 possible routes to check
• For 5 cities, there are 60 possible routes
• For 6 cities, there are 360 possible routes
• For 10 cities, there are over 1.8 million
possible routes. If a computer calculated 10
routes per second, it would take 2 days before
it found the shortest.
32. LOGIC STRUCTURES
• IF ( statement ) THEN ( action )
• IF ( statement ) THEN ( action ) ELSE ( action )
• WHILE ( statement ) THEN ( action )
• FUNCTION ( group of actions )
33. GROUP ACTIVITY #1
Write an algorithm for one of the following:
• The Nutbush
• The Macarena
• The Hokey Pokey
• The Chicken Dance
34. GROUP ACTIVITY #2
Write an algorithm for making a paper plane.
Then swap with another group and see if they
can follow your instructions.
35. GROUP ACTIVITY #3
Write an algorithm for a driverless car
approaching an intersection:
• What road rules come into play?
• What should the vehicle be on the lookout
for?
• What actions should the vehicle take?