SlideShare a Scribd company logo
Learn to
Think Like A Coder
Andrew Marks
@entreprenerds
“Everybody should learn how to program a
computer because it teaches you how to think.”
- Steve Jobs
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
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
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
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.
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”.
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
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
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.
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
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:
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 
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
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
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
SORTING ALGORITHMS
Bubble Sort:
Sort these numbers: 5, 4, 2, 1, 3
SORTING ALGORITHMS
Merge Sort
Sort these numbers: 5, 2, 4, 6, 1, 3, 2, 6
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…
This is an unstable marriage
Queen of Hearts would prefer King of Spades
King of Spades would prefer Queen of Hearts
+
+
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
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
GOOGLE PAGERANK ALGORITHM
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…
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?
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.
LOGIC STRUCTURES
• IF ( statement ) THEN ( action )
• IF ( statement ) THEN ( action ) ELSE ( action )
• WHILE ( statement ) THEN ( action )
• FUNCTION ( group of actions )
GROUP ACTIVITY #1
Write an algorithm for one of the following:
• The Nutbush
• The Macarena
• The Hokey Pokey
• The Chicken Dance
GROUP ACTIVITY #2
Write an algorithm for making a paper plane.
Then swap with another group and see if they
can follow your instructions.
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?

More Related Content

Similar to Learn to Think Like a Coder

3 solving problems
3 solving problems3 solving problems
3 solving problems
hccit
 

Similar to Learn to Think Like a Coder (20)

computational_thinking_gcse.pptx
computational_thinking_gcse.pptxcomputational_thinking_gcse.pptx
computational_thinking_gcse.pptx
 
GRADE 6 ALGORITHM.pptx
GRADE 6 ALGORITHM.pptxGRADE 6 ALGORITHM.pptx
GRADE 6 ALGORITHM.pptx
 
20180324 zen and the art of programming
20180324 zen and the art of programming20180324 zen and the art of programming
20180324 zen and the art of programming
 
3 solving problems
3 solving problems3 solving problems
3 solving problems
 
Testing for everyone agile yorkshire
Testing for everyone agile yorkshireTesting for everyone agile yorkshire
Testing for everyone agile yorkshire
 
What is an algorithm?
What is an algorithm?What is an algorithm?
What is an algorithm?
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Application of algorithm in real life
Application of algorithm in real lifeApplication of algorithm in real life
Application of algorithm in real life
 
Writing algorithms
Writing algorithmsWriting algorithms
Writing algorithms
 
Software Development is Upside Down
Software Development is Upside DownSoftware Development is Upside Down
Software Development is Upside Down
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptx
 
Counting and Sequences
Counting and SequencesCounting and Sequences
Counting and Sequences
 
Problem Solving (Lecture)
Problem Solving (Lecture)Problem Solving (Lecture)
Problem Solving (Lecture)
 
Machine Learning for Designers - UX Camp Switzerland
Machine Learning for Designers - UX Camp SwitzerlandMachine Learning for Designers - UX Camp Switzerland
Machine Learning for Designers - UX Camp Switzerland
 
AS computing
AS computingAS computing
AS computing
 
Prompt-Engineering-Lecture-Elvis learn prompt engineering
Prompt-Engineering-Lecture-Elvis learn prompt engineeringPrompt-Engineering-Lecture-Elvis learn prompt engineering
Prompt-Engineering-Lecture-Elvis learn prompt engineering
 
Machine Learning for Designers
Machine Learning for DesignersMachine Learning for Designers
Machine Learning for Designers
 
Greedy algorithm for design and analysis
Greedy algorithm for design and analysisGreedy algorithm for design and analysis
Greedy algorithm for design and analysis
 
DutchMLSchool. Introduction to Machine Learning with the BigML Platform
DutchMLSchool. Introduction to Machine Learning with the BigML PlatformDutchMLSchool. Introduction to Machine Learning with the BigML Platform
DutchMLSchool. Introduction to Machine Learning with the BigML Platform
 
Machine Learning on Azure - AzureConf
Machine Learning on Azure - AzureConfMachine Learning on Azure - AzureConf
Machine Learning on Azure - AzureConf
 

More from Andrew Marks

More from Andrew Marks (12)

Wordpress for Business
Wordpress for BusinessWordpress for Business
Wordpress for Business
 
Google Analytics Essential Training
Google Analytics Essential TrainingGoogle Analytics Essential Training
Google Analytics Essential Training
 
A Guide to Google My Business
A Guide to Google My BusinessA Guide to Google My Business
A Guide to Google My Business
 
How WordPress Sites Get Hacked
How WordPress Sites Get HackedHow WordPress Sites Get Hacked
How WordPress Sites Get Hacked
 
An Introduction to Gutenberg, WordPress's New Editor
An Introduction to Gutenberg, WordPress's New EditorAn Introduction to Gutenberg, WordPress's New Editor
An Introduction to Gutenberg, WordPress's New Editor
 
An Introduction to WordPress Hooks
An Introduction to WordPress HooksAn Introduction to WordPress Hooks
An Introduction to WordPress Hooks
 
Processing Client Payments from your WordPress Website
Processing Client Payments from your WordPress WebsiteProcessing Client Payments from your WordPress Website
Processing Client Payments from your WordPress Website
 
GDPR - What You Need To Know
GDPR - What You Need To KnowGDPR - What You Need To Know
GDPR - What You Need To Know
 
10 Tips for Optimising WordPress
10 Tips for Optimising WordPress10 Tips for Optimising WordPress
10 Tips for Optimising WordPress
 
An (Updated) Introduction to Gutenberg
An (Updated) Introduction to GutenbergAn (Updated) Introduction to Gutenberg
An (Updated) Introduction to Gutenberg
 
Ultimate Guide to WordPress Multisite
Ultimate Guide to WordPress MultisiteUltimate Guide to WordPress Multisite
Ultimate Guide to WordPress Multisite
 
Ultimate Guide to Advanced Custom Fields
Ultimate Guide to Advanced Custom FieldsUltimate Guide to Advanced Custom Fields
Ultimate Guide to Advanced Custom Fields
 

Recently uploaded

Article writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxArticle writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptx
abhinandnam9997
 
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
aagad
 

Recently uploaded (12)

The Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case StudyThe Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case Study
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
 
ER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAEER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAE
 
The Best AI Powered Software - Intellivid AI Studio
The Best AI Powered Software - Intellivid AI StudioThe Best AI Powered Software - Intellivid AI Studio
The Best AI Powered Software - Intellivid AI Studio
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
 
Article writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxArticle writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptx
 
Stay Ahead with 2024's Top Web Design Trends
Stay Ahead with 2024's Top Web Design TrendsStay Ahead with 2024's Top Web Design Trends
Stay Ahead with 2024's Top Web Design Trends
 
The AI Powered Organization-Intro to AI-LAN.pdf
The AI Powered Organization-Intro to AI-LAN.pdfThe AI Powered Organization-Intro to AI-LAN.pdf
The AI Powered Organization-Intro to AI-LAN.pdf
 
1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...
 
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
 

Learn to Think Like a Coder

  • 1. Learn to Think Like A Coder Andrew Marks @entreprenerds
  • 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
  • 17. SORTING ALGORITHMS Bubble Sort: Sort these numbers: 5, 4, 2, 1, 3
  • 18. SORTING ALGORITHMS Merge Sort Sort these numbers: 5, 2, 4, 6, 1, 3, 2, 6
  • 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?