DOC PREVIEW
Duke CPS 004 - Lecture

This preview shows page 1 out of 4 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Compsci 06/101, Spring 2011 4.1 Compsci 6: PFTW  Problem solving and (Python) programming  What are the steps in solving an APT?  How do you get better at this?  How do you avoid getting frustrated? Cope with it?  Practice selection, abstraction, looping  In the context of solving problems  El hombre bebe  Get ready for first assignment  Difference between assignment and APTs? Compsci 06/101, Spring 2011 4.2 How to solve an APT  Two very, very, very important steps 1. How to solve the problem with Paper, Pencil, (Calculator) 2. How to translate problem-solving to Python  Both steps can be hard, vocabulary and language are initially a real barrier  The more experience you have with Python, the easier step 2 will get  The more you understand the idioms and power of the language the more you can let step 2 influence step 1  Step 1 is key, without it you won’t get anywhere Compsci 06/101, Spring 2011 4.3 APT Pancake  How do you solve this problem?  First steps: are there simple cases that can be solved immediately? • What are these for the pancake problem? • How will you identify with Python?  Sometimes it helps to know if you are on track, use Python to check your paper and pencil work  Get specific, solve for 7, not N  Fix one parameter, vary the other  Identify the cases and continue Compsci 06/101, Spring 2011 4.4 Three pancakes in a two-cake pan…  Number of cakes in the system  First 5 minutes  Number of cakes in the system  Second 5 minutes ABCB'ACCompsci 06/101, Spring 2011 4.5 Three pancakes in a two-cake pan…  Number of cakes in the system  Third 5 minutes  How many minutes to cook all three pancakes? A'C'B''A'' B'' C''Compsci 06/101, Spring 2011 4.6 How to teach pancake flipping  http://www.youtube.com/watch?v=W_gxLKSsSIE  Is this computer science?  For longer, more complex robotic tasks • http://www.youtube.com/watch?v=4usoE981e7I  Back to specifics:  Capacity = 7  Numcakes = 1,2,…7?  Numcakes = 8,9,10,11,12,13,14?  Numcakes = 15,16,17,18,19,20?  Is seven special? 6? 5? 3? Compsci 06/101, Spring 2011 4.7 Eclipse Interlude  Finishing the Pancake problem  Translating problem-solving ideas to code Compsci 06/101, Spring 2011 4.8 Lessons: special cases, abstractions  There are special cases in many, many problems  Identifying them is important  Abstracting them away when possible is important  Example: SilverDistance APT • Instead of four quadrants/cases, reducible to two? • Instead of (x,y) and (z,w) translate to (0,0) and (z-x,w-y)  Translating ideas into (Python) code  How do we create interesting “heads”, “totem poles” ?  How do create software for identikit?  How do we create Facebook, Foursquare, …Compsci 06/101, Spring 2011 4.9 How do you solve a problem like …?  Translating English to Piglatin  Why is this fascinating?  http://www.google.com/webhp?hl=xx-piglatin  Is this like translating English to German?  Is it like translating Python to bytecode?  “downplay their unique quiet strength”  “ownplayday eirthay uniqueway ietquay engthstray”  What are the rules for pig-latin? See APT Compsci 06/101, Spring 2011 4.10 APT Piglatin  How do you solve this problem?  First steps: are there simple cases that can be solved immediately? • What are these for the piglatin problem? • How will you identify with Python?  Words that begin with … • Vowel • Foods that begin with the letter ‘q’ for 200 Alex  Translation to Python  First ‘q’, then vowels Compsci 06/101, Spring 2011 4.11 Three versions of is_vowel def is_vowel(ch): if ch =='e': return True if ch == 'a': return True if ch == 'i': return True if ch == 'o': return True if ch == 'u': return True return False def is_vowel(ch): c = "aeiou".count(ch) if c > 0: return True else return False def is_vowel(ch): return "aeiou".count(ch) > 0 Compsci 06/101, Spring 2011 4.12 Piglatin, age-stay one-way def convert(s): if s[0] == 'q': return s[2:]+"quay" if is_vowel(s[0]): return s+"way"  Review from last lab: slicing, concatenation, index  Where does string-indexing start?  What does slice with a single parameter do?Compsci 06/101, Spring 2011 4.13 Piglatin, age-stay o-tway def convert(s): if s[0] == 'q': return s[2:]+"quay" if is_vowel(s[0]): return s+"way" if is_vowel(s[1]): return s[1:]+s[0]+"ay" if is_vowel(s[2]): return s[2:]+s[:2]+"ay" if is_vowel(s[3]): return s[3:]+s[:3]+"ay" if is_vowel(s[4]): return s[4:]+s[:4]+"ay" Compsci 06/101, Spring 2011 4.14 Piglatin, age-stay ee-threay def convert(s): if s[0] == 'q': return s[2:]+"quay" if isvowel(s[0]): return s + "way" for index in range(1,len(s)): if isvowel(s[index]): return s[index:]+s[:index]+"ay"  Generalize/parameterize by what varies  What does a loop do? it repeats! Compsci 06/101, Spring 2011 4.15 What does this do? def changeup(s): rep = "" for ch in s: rep = rep + ch*2 return rep  What's new here, what's similar to what we know?  What does it mean to loop over a string?  How do we know it's a string?  Code experiments to help reason (or just type and run?)  Look again at Uppity.py? Compsci 06/101, Spring 2011 4.16 Dawson Engler  ACM Hopper Award 2008 "In his papers on automated program checking, Dawson Engler introduces and develops powerful techniques and tools for practical program analysis for finding errors in code."  Started coverity.com  Very successful startup to find errors in code 


View Full Document

Duke CPS 004 - Lecture

Documents in this Course
Lecture

Lecture

18 pages

Chapter 7

Chapter 7

18 pages

Chapter 9

Chapter 9

15 pages

Java 1

Java 1

24 pages

Java 3

Java 3

11 pages

Lecture

Lecture

10 pages

Chapter 4

Chapter 4

28 pages

Chap 2

Chap 2

16 pages

Graphics

Graphics

20 pages

Lecture

Lecture

12 pages

HTML

HTML

16 pages

Java 1

Java 1

6 pages

Chapter 4

Chapter 4

16 pages

The Plan

The Plan

25 pages

Lecture

Lecture

16 pages

Chapter 6

Chapter 6

21 pages

Lecture

Lecture

18 pages

Lecture

Lecture

23 pages

Lecture

Lecture

16 pages

Lecture

Lecture

19 pages

Lecture

Lecture

12 pages

Lecture

Lecture

5 pages

Lecture

Lecture

26 pages

Lecture

Lecture

16 pages

Chapter 7

Chapter 7

23 pages

Lecture

Lecture

21 pages

Lecture

Lecture

4 pages

Lecture

Lecture

4 pages

Lecture

Lecture

8 pages

Lecture

Lecture

4 pages

Lecture

Lecture

10 pages

Chapter 4

Chapter 4

32 pages

Java

Java

4 pages

CompSci 4

CompSci 4

18 pages

Lecture

Lecture

26 pages

CompSci 4

CompSci 4

12 pages

HTML

HTML

17 pages

Lecture

Lecture

16 pages

Chapter 5

Chapter 5

22 pages

Chapter 4

Chapter 4

10 pages

Chapter 2

Chapter 2

15 pages

Chapter 8

Chapter 8

14 pages

Lecture

Lecture

15 pages

Load more
Download Lecture
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?