Professional Documents
Culture Documents
Tuesday, February 5, 13
Tuesday, February 5, 13
Show of hands
Who has programmed before? Who knows Python? Who wants to be a CS major? Who thinks theyre going to be bad at programming? Who thinks they will need to program in their life? Whos here because its a requirement?
Tuesday, February 5, 13
Introductions
Tuesday, February 5, 13
Course objectives
Tuesday, February 5, 13
Course objectives
Prepare students without programming experience for course VI Help non-course VI students write programs Map scientic problems into computational framework Provide students with competence in computational problem solving (useful for urops & summer jobs)
Tuesday, February 5, 13
Is programming hard?
Programming is not hard But you often dont get it right at rst - like most things - Persevere, edit, debug, divide and conquer
Everyone can be a programmers - Not necessarily a software architect who handles millions of lines of code - But everyone can use programming to solve practical problems
Tuesday, February 5, 13
Administrivia
Tuesday, February 5, 13
Administrivia
Mostly web-based: stellar, piazza Signup on website for recitations Weekly programming problem sets 2 evening quizzes. First one around March 7 Final exam, closed book, 2 sheets of notes Textbook MITx material - lectures, nger exercises, low-grade version of book
Tuesday, February 5, 13
Collaboration policy
Collaborate, dont plagiarize - Talk about psets, but write your own code - Good idea not to look at other peoples code
Tuesday, February 5, 13
Mostly same material, slightly different presentation and order Dont freak out too much if you cant answer all questions on old quizzes - But freak out a little bit
Tuesday, February 5, 13
Path planning
Airfare optimization
Tuesday, February 5, 13
Biology
Pandora, Spotify
Tuesday, February 5, 13
Tuesday, February 5, 13
Simulation
Search
http://en.wikipedia.org/wiki/File:PageRanks-Example.svg https://dhs.stanford.edu/algorithmic-literacy/accessing-data/
Tuesday, February 5, 13
Tuesday, February 5, 13
Robots
Tuesday, February 5, 13
Tuesday, February 5, 13
Tuesday, February 5, 13
Medical imaging
Tuesday, February 5, 13
Computational thinking
Cognition as algorithms Human vision & computer vision Genetics as information processing
Tuesday, February 5, 13
Scrabble/Words With Friends inspired game Encryption/decryption RSS ltering Simple robot simulation Virus spread simulation Election prediction using randomized simulation Course load optimization Clustering census data
Tuesday, February 5, 13
Tuesday, February 5, 13
Yearbook
Small team and too many photos/names/index to handle. Were about to miss the print deadline. After an hour of code: Script to automatically generate layout from pictures+names Unfortunately no duck-face correction script
Tuesday, February 5, 13
You choose among three doors - one of them allows you to win a car
A B
Then the host tells you, for one of the doors you didnt choose, that it doesnt have a car You get a chance to change your mind: what should you do? Simulation was 20 lines of code
Tuesday, February 5, 13
Simple problems
Tennis game probabilities - 60 lines of code Is 2048 the last power of two with only even digits? - 20 lines of code Web site ltering with chicken feet - 10 lines of easy code Designating TA volunteers - 3 lines of Pyhton~
Tuesday, February 5, 13
Photo collages
Tuesday, February 5, 13
Photo collages
Tuesday, February 5, 13
Pentimento
Handw
Tuesday, February 5, 13
Be
Tuesday, February 5, 13
Part of pset 0 Anything from frivolous to big challenges Well try to give you feedback: - A Harvard student could do it - You can do it at the end of 6.00 - You can do it at the end of course VI - Youll need a big team of programmers - So hard theyll create a Nobel prize in computer science just for this - This is the next Microsoft/Google/Facebook. Weve already stolen and patented your idea
Tuesday, February 5, 13
What is Computation?
Tuesday, February 5, 13
Programming is empowering and cool Imperative knowledge Computers are dumb and just follow steps Variables & assignment
Tuesday, February 5, 13
Youre the computer! n=10 while n1: if isEven(n): n=n/2 else: n=n*3+1
Tuesday, February 5, 13
Python tutor
http://www.pythontutor.com/
Tuesday, February 5, 13
Tuesday, February 5, 13
Elements of a program
Variable
n=10 assignment
while n 1: control
test
if even(n): control
assignment
test
n=n/2
arithmetic
else: n=n*3+1
Tuesday, February 5, 13
Dont forget
The computer has no purpose The computer doesnt understand the task The computer just does what you tell it to do
Tuesday, February 5, 13
Tuesday, February 5, 13
Declarative denition of
Tuesday, February 5, 13
Imperative version of pi
Area of circle of radius 1 Generate lots of points inside [-1 1] square Count point inside circle - they satisfy x*x+y*y<1
Tuesday, February 5, 13
Computing pi
N=1000.0 numberInCircle=0.0 x=-1.0 while x<1.0: y=-1.0 while y<1.0: if x*x+y*y<1: numberInCircle=numberInCircle+1 y=y+1/N x=x+1/N print numberInCircle/(N*N)
Tuesday, February 5, 13
Imperative (Heron algorithm) - start with rough guess, e.g. x=N - While x2 too different from N - x=0.5*(x+N/x)
Tuesday, February 5, 13
Tuesday, February 5, 13
Why Python?
Easy syntax, concise Supports all styles of programming Widely used in science and engineering - lots of useful library Easy to transfer knowledge to other languages Cons: can be slow - but you can speed it up with Pypi
Tuesday, February 5, 13
IDLE
Shell - where results are printed - where user-input is entered - can be used for on-the-y pogramming and experiments
Tuesday, February 5, 13
Basic elements
Tuesday, February 5, 13
The = challenge
= in computer science is very different from = in math the left hand side of = is always a variable name = means that the result of the right expression gets stored in the variable some languages use <- instead of = to be clearer to make matters worse, there is a test to see if two expressions are equal, and in Python its
Tuesday, February 5, 13
Computer science is cool and useful Imperative knowledge Computers are dumb and just follow steps Variables & assignment = means that the variable on the left stores a new value
Tuesday, February 5, 13