IS 313 Today What's ahead? I see I'm not the only one loopy around here… 10/7 Lec 5 ~ today, now! HMC standings!? 10/8 homework 3 due 10/14 Lec 6 ~ "dictionaries"

Slides:



Advertisements
Similar presentations
Chapter 11 Introduction to Programming in C
Advertisements

CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
Computer Programming w/ Eng. Applications
Anne McGrath 16 th February  Review of what we have learned so far.  Angled brackets surround HTML tags.  The words between the angled brackets.
Review for Final Exam Dilshad M. NYU. In this review Arrays Pointers Structures Java - some basic information.
 Caesar used to encrypt his messages using a very simple algorithm, which could be easily decrypted if you know the key.  He would take each letter.
16-May-15 Sudden Python Drinking from the Fire Hose.
Computer Science 1620 Loops.
HW 3: Problems 2&3. HW 3 Prob 2:Encipher encipher( S, n ) takes as input a string S and a non-negative integer n between 0 and 25. This function returns.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
CS 106 Introduction to Computer Science I 10 / 09 / 2006 Instructor: Michael Eckmann.
Introduction to Python
R-1 University of Washington Computer Programming I Lecture 17: Multidimensional Arrays © 2000 UW CSE.
What's ahead? Conway gives a whole new outlook on "loopy" ! John Conway 10/18 no class - Fall break 10/19 no new hw due 10/11 Dynamic & binary data 10/12.
Cryptography Programming Lab
“Everything Else”. Find all substrings We’ve learned how to find the first location of a string in another string with find. What about finding all matches?
Spring  Evolving Lists & Lights On!  Caesar Cipher  Looks Good!
Elements of a C++ program 1. Review Algorithms describe how to solve a problem Structured English (pseudo-code) Programs form that can be translated into.
Handling Lists F. Duveau 16/12/11 Chapter 9.2. Objectives of the session: Tools: Everything will be done with the Python interpreter in the Terminal Learning.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
The not-so-subtle art of singling out the best (and worst) of anything… Computing with language Computing to the max You know this would make me hungry…
CS 5 Today HW 9 (lab + 2 probs) due Sunday, 11/8 at midnight Dizzying arrays of possibilities… John Conway Carl Gauss This week’s credits: Exam 2 on Mon.,Tue.
EECS 110: Lec 8: Lists of Lists Aleksandar Kuzmanovic Northwestern University
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #005 (April somthin, 2015)
Collecting Things Together - Lists 1. We’ve seen that Python can store things in memory and retrieve, using names. Sometime we want to store a bunch of.
Downloading and Installing Autodesk Revit 2016
The Game of Life A simulation of "life". From simple rules, complex behavior arises Rules –A cell that is alive and has fewer than two live neighbors dies.
EECS 110: Lec 12: Mutable Data Aleksandar Kuzmanovic Northwestern University
This week in CS 5 HW 9 (2 problems) M/T sections W/Th sections due Sunday, 11/4 at midnight due Monday, 11/5 at midnight Recitation for HW9 -- Friday 11/2.
… Caesar Cipher: encipher encipher( 'gv vw dtwvg', 0 ) encipher( 'gv vw dtwvg', 1 ) encipher( 'gv vw dtwvg', 2 ) encipher( 'gv vw dtwvg', 3 ) encipher(
Compsci 06/101, Fall What will you do in Compsci 6 Today? l Learn about selection and if/else statements  In context of solving problems  Understanding.
CS50 Week 2. RESOURCES Office hours ( Lecture videos, slides, source code, and notes (
CSC 107 – Programming For Science. The Week’s Goal.
With Python.  One of the most useful abilities of programming is the ability to manipulate files.  Python’s operations for file management are relatively.
Downloading and Installing Autodesk Inventor Professional 2015 This is a 4 step process 1.Register with the Autodesk Student Community 2.Downloading the.
Looping and Counting Lecture 3 Hartmut Kaiser
Computing Science 1P Large Group Tutorial: Lab Exam & Class Test Simon Gay Department of Computing Science University of Glasgow 2006/07.
EECS 110: Lec 8: Lists of Lists Aleksandar Kuzmanovic Northwestern University
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
Python Let’s get started!.
Ionut Trestian Northwestern University
Fall 2015, Kevin Quinn CSE373: Data Structures & Algorithms Lecture 25: Problem Solving CSE373: Data Structures and algorithms1.
EECS 110: Lec 12: Mutable Data Aleksandar Kuzmanovic Northwestern University
GCSE Computing: Programming GCSE Programming Remembering Python.
EECS 110: Lec 8: Lists of Lists Aleksandar Kuzmanovic Northwestern University
NXT File System Just like we’re able to store multiple programs and sound files to the NXT, we can store text files that contain information we specify.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
ENGINEERING 1D04 Tutorial 2. What we’re doing today More on Strings String input Strings as lists String indexing Slice Concatenation and Repetition len()
EECS 110: Lec 8: Lists of Lists
Course Contents KIIT UNIVERSITY Sr # Major and Detailed Coverage Area
EECS 110: Lec 12: Mutable Data
Spring 2010 EECS 110: Homework III.
Caesar Cipher: encipher
Whatcha doin'? Aims: To understand the Caesar Cipher.
Other Kinds of Arrays Chapter 11
Homework 3 Problem 0 If you liked the article on the DNA computer, check the following: Biocomputer and Memory Built Inside Living Bacteria IEEE Spectrum,
More Loop Examples Functions and Parameters
HMC’s Galileo Auditorium Some of Cope’s generated MP3s:
Using files Taken from notes by Dr. Neil Moore
Ionut Trestian Northwestern University
We’re moving on to more recap from other programming languages
Fundamentals of Data Representation
2D Array and Matrix.
functions: argument, return value
Northwestern University
Symmetry and Congruence
EECS 110: Lec 12: Mutable Data
More 2D Array and Loop Examples Functions and Parameters
2D Array and Matrix Application: Game of Life
Presentation transcript:

IS 313 Today What's ahead? I see I'm not the only one loopy around here… 10/7 Lec 5 ~ today, now! HMC standings!? 10/8 homework 3 due 10/14 Lec 6 ~ "dictionaries" 10/15 homework 4 due 10/28 Lec 7 ~ classes & objects 11/29 homework 5 due Strings, lists, and loops ~ beyond 1d ! HMC Fall Break

An image alternative…

#### for row in range(3): print “#”*4 Print 4 rows Creates line to print print automatically adds a newline Output ASCII Art

$$$$ for row in range(3): print '$'*4 Output A closer look…

$$$$ for row in range(3): print '$'*4 Output No string * ! For this problem, string multiplication is not allowed.

Without string multiplication… for row in range(3): for col in range(4): print '$' Print 3 rows print 4 chars on each line nested loops! Output ? (columns)

Without string multiplication… for row in range(3): for col in range(4): print '$', Print 3 rows print 4 chars on each line nested loops! Output ? (columns) Comma suppresses newline

Without string multiplication… Print 3 rows print 4 chars on each line nested loops! tracking cols and rows! (columns) for row in range(3): for col in range(4): print '$', print Comma suppresses newline plain print produces newline $ $

Tracking rows and columns for row in range(3): for col in range(4): print '$', print $ $ Output:

Variations! for row in range( ): for col in range( ): print '$', print def rectangle( width, height ): """ prints a rectangle of $ """

"Quiz" for row in range( 3 ): for col in range( 7 ): print ____________, print Fill in each block of code so that it will print the lines above it. for row in range( 3 ): for col in range( 7 ): print ____________, print for row in range( 3 ): for col in range( 7 ): print ______________, print for row in range( 3 ): for col in range( 7 ): print _____________, print

Beyond boxes… # # # # # # # # # # # # # # What code would print this “ASCII triangle” ? with height rows and width columns… rows cols for row in range(1,7): for col in range( ):

A video alternative ?!?

A simpler web interface… HTML HyperText Markup Language and the beautiful Tower of Pisa

A simpler web interface… HTML CGI HyperText Markup Language Common Gateway Interface ~ HTML forms and the beautiful Tower of Pisa

A simpler web interface… HTML CSSAJAXJavascript CGI HyperText Markup Language Common Gateway Interface ~ HTML forms and the beautiful Tower of Pisa Others!

Web resources ~ on the Web started by every technology - and acronym - you'd ever want to know… Tim Berners-Lee

This week… Get the pure-Python webserver and run it. Make sure the example "application" works… Change the example "application" so that you … web-implement one of the ASCII art problems be sure that you take in the inputs you need Checklist: watch out for conversions between ints and strings! make small changes and test as you go… This is not webdesign!

Strings vs. language strings language / words / phrases numbers / bits ideas / meaning computers humans

Hugh Loebner How could a computer demonstrate intelligence? Alan Turing Turing Test Confederates $100,000 Loebner prize for passing the Turing test, held each year in the London Museum of Science

Parsing for real (S (S (NP Time flies) (VP like (NP an arrow))), but (S (NP fruit) (VP flies (PP like (NP a banana)))).) Time flies like an arrow, but fruit flies like a banana. - Marx " "time" N NOM " "fly" V "fly" N NOM " "like" " "an" DET CENTRAL ART " "arrow" N NOM " "but" " "fruit_fly" N NOM " "like" " "a" DET CENTRAL ART " "banana" N NOM " I like bananas, too! parseTree #1 parseTree #2

Some conversations… Jabb:... Greetings! Jabberwock is at the keyboard. You:... How are you doing? Jabb:... Everything is running smoothly. And how are you doing? You:... Pretty well. It's quiet around here this morning. Jabb:... Does that mean you agree? You:... Agree with what? Jabb:... Sure and 2006 winner: Rollo Carpenter's Jabberwacky

Loebner results no human averaged less than 80 four humans and four machines participated

Some conversations… You: Hi. you’re the program that won the Loebner competition, right? SID: Albert One was the last winner of the Loebner Contest. I am something else entirely. You: Impressive. Do you have any areas of particular expertise?

Some conversations… You: Hi. you’re the program that won the Loebner competition, right? SID: Albert One was the last winner of the Loebner Contest. I am something else entirely. You: Impressive. Do you have any areas of particular expertise? SID: I appreciate that. You: Not so impressive. If I ask a question after a statement, do you ignore the question?

Some conversations… You: Hi. you’re the program that won the Loebner competition, right? SID: Albert One was the last winner of the Loebner Contest. I am something else entirely. You: Impressive. Do you have any areas of particular expertise? SID: I appreciate that. You: Not so impressive. If I ask a question after a statement, do you ignore the question? SID: I am free to do as I please. You: Wow! Are you talking free will vs. determinism?

Some conversations… You: Hi. you’re the program that won the Loebner competition, right? SID: Albert One was the last winner of the Loebner Contest. I am something else entirely. You: Impressive. Do you have any areas of particular expertise? SID: I appreciate that. You: Not so impressive. If I ask a question after a statement, do you ignore the question? SID: I am free to do as I please. You: Wow! Are you talking free will vs. determinism? SID: I don’t think wow am i talking free will vs. determinism, but I can’t be 100% sure of that.

Computing with language strings language / words / phrases numbers / bits ideas / meaning open questions in AI … how strings are represented and stored computing with language - recognizing English! (3) (2) (1)

Caesar Cipher 'Bzdrzq bhogdq? H oqdedq Bzdrzq rzkzc.' 'Caesar cipher? I prefer Caesar salad.'

Caesar Cipher: encipher encipher( 'gv vw dtwvg', 0 ) encipher( 'gv vw dtwvg', 1 ) returns 'gv vw dtwvg' 'hw wx euxwh'

Caesar Cipher: encipher encipher( 'gv vw dtwvg', 0 ) encipher( 'gv vw dtwvg', 1 ) encipher( 'gv vw dtwvg', 2 ) encipher( 'gv vw dtwvg', 3 ) encipher( 'gv vw dtwvg', 4 ) encipher( 'gv vw dtwvg', 25 ) returns 'gv vw dtwvg' 'hw wx euxwh' 'ix xy fvyxi' 'jy yz gwzyj' 'kz za hxazk' 'fu uv csvuf' encipher( s, n ) should return the string s with each alphabetic character shifted/wrapped by n places in the alphabet...

ASCII American Standard Code for Information Interchange == low-tech art form!

__ _,___,-'",-=-. __,-- _ _,-'_)_ (""`'-._\ `. _,' __ |,',-' __),- /. |,'_,--' | -' _)/ `\,',',',-'_,` :,',-',(,-( :,',-', _ ; /,-._/`---' / / (____)(----. ),' / ( `.__, /\ /, : ;-.___ /__\/| |,' `--. -,\ | : / \.__/ \ (__ \ |_ \,`-, * / _|,\ \,' `-.,'_,-' \ (_\,-','\")--,'-' __\ \ / //,'|,--' `-. `-. `-/ \' | _,' `. `-._ / `--'/ \ -doh!-,' | \ / | \,-' | / / | -' ASCII American Standard Code for Information Interchange == low-tech art form! ASCII-betical order: Homer min Marge $42.42 [:^)] bart lisa max

ASCII ASCII is a table that tells the computer how to represent characters as #s American Standard Code for Information Interchange chr ord convert to number convert to char. You know, these functions kind of look familiar!

ASCII ASCII is a table that tells the computer how to represent characters as bits! 8 bits = 1 byte The SAME bits represent integers, if the variable has type int instead of str American Standard Code for Information Interchange type: str type: int bits name: value: '*' 42 Identical bits are stored in each variable! The types determine how to interpret the bits; the names don't matter at all…

chr and ord chr( n ) ord( c ) Input: an integer in range(255) Input: a string of one character, c abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ ASCII VALUES Output: a one-char. string of that ASCII value Output: an integer, the ASCII value of c CONVERTERS for i in range(128): print 'i and chr(i) are', i, chr(i) try this

chr and ord chr(66) is 'B' ord('a') is 97 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 90 ASCII VALUES What is chr( ord('i')+13 ) What is chr( ord('W')+13 ) ? How can we wrap this around?

Rot 13 def adv13( c ): """ rotates c by 13 chars, "wrapping" as needed NON-LETTERS DO NOT CHANGE! """ if 'a' <= c <= 'z': new_ord = ord(c) + 13 if new_ord <= ord('z'): return chr(new_ord) # no wrapping else: return elif else: How would you rotate an entire string?

Caesar Cipher: decipher >>> decipher('Bzdrzq bhogdq? H oqdedq Bzdrzq rzkzc.') 'Caesar cipher? I prefer Caesar salad.' >>> decipher('Hu lkbjhapvu pz doha ylthpuz hmaly dl mvynla '\ 'lclyfaopun dl ohcl slhyulk.') 'An education is what remains after we forget everything we have learned.' But how ? >>> decipher('gv vw dtwvg')

Caesar Cipher: decipher >>> decipher('gv vw dtwvg') CaesarBrutus Strategy using max : (1) consider all possible answers (2) give them each a score (3) loop through them all and find the one with the max score! gv vw dtwvg hw wx euxwh ix xy fvyxi jy yz gwzyj kz za hxazk la ab iybal mb bc jzcbm nc cd kadcn od de lbedo pe ef mcfep qf fg ndgfq rg gh oehgr sh hi pfihs ti ij qgjit uj jk rhkju vk kl silkv wl lm tjmlw xm mn uknmx yn no vlony zo op wmpoz ap pq xnqpa bq qr yorqb cr rs zpsrc ds st aqtsd et tu brute fu uv csvuf all 26 possibilities Score for "Englishness"? up to you…

Caesar Cipher: decipher >>> decipher('gv vw dtwvg') 'od de lbedo' CaesarBrutus Strategy using max : (1) consider all possible answers (2) give them each a score (3) use our techniques with max [0, 'cr rs zpsrc'] [0, 'gv vw dtwvg'] [0, 'jy yz gwzyj'] [0, 'mb bc jzcbm'] [0, 'qf fg ndgfq'] [0, 'wl lm tjmlw'] [1, 'bq qr yorqb'] [1, 'ds st aqtsd'] [1, 'nc cd kadcn'] [1, 'vk kl silkv'] [1, 'xm mn uknmx'] [2, 'ap pq xnqpa'] [2, 'hw wx euxwh'] [2, 'ix xy fvyxi'] [2, 'kz za hxazk'] [2, 'rg gh oehgr'] [2, 'sh hi pfihs'] [2, 'uj jk rhkju'] [2, 'yn no vlony'] [3, 'fu uv csvuf'] [3, 'pe ef mcfep'] [3, 'ti ij qgjit'] [3, 'zo op wmpoz'] [4, 'et tu brute'] [4, 'la ab iybal'] [4, 'od de lbedo'] all 26 possibilities won't always be correct! number-of-vowels score

Caesar Cipher: decipher >>> decipher('gv vw dtwvg') 'et tu brute' CaesarBrutus Strategy using max : (1) consider all possible answers (2) give them each a score (3) use our techniques with max [0.4680, 'jy yz gwzyj'] [0.4960, 'mb bc jzcbm'] [0.5420, 'uj jk rhkju'] [0.5567, 'ix xy fvyxi'] [0.5597, 'qf fg ndgfq'] [0.5718, 'fu uv csvuf'] [0.5753, 'bq qr yorqb'] [0.5833, 'kz za hxazk'] [0.5859, 'xm mn uknmx'] [0.5880, 'gv vw dtwvg'] [0.5902, 'vk kl silkv'] [0.6110, 'ap pq xnqpa'] [0.6304, 'zo op wmpoz'] [0.6318, 'wl lm tjmlw'] [0.6717, 'cr rs zpsrc'] [0.6735, 'hw wx euxwh'] [0.6963, 'nc cd kadcn'] [0.7153, 'ti ij qgjit'] [0.7398, 'la ab iybal'] [0.7442, 'yn no vlony'] [0.7867, 'pe ef mcfep'] [0.7880, 'sh hi pfihs'] [0.7918, 'rg gh oehgr'] [0.8213, 'ds st aqtsd'] [0.8609, 'od de lbedo'] [0.9082, 'et tu brute'] all 26 possibilities letter- probability score not always correct, but better!

The caesar cipher problem offers lots of freedom… Think a bit about how you'll approach it! Questions / Lab time…

Caesar Cipher: decipher >>> decipher('Bzdrzq bhogdq? H oqdedq Bzdrzq rzkzc.') 'Caesar cipher? I prefer Caesar salad.' >>> decipher('Hu lkbjhapvu pz doha ylthpuz hmaly dl mvynla '\ 'lclyfaopun dl ohcl slhyulk.') 'An education is what remains after we forget everything we have learned.' But how to do this… ? >>> decipher('Uifz xpsl ju pvu xjui b qfodjm!') ? >>> decipher('gv vw dtwvg') ?

Caesar Cipher: decipher >>> decipher('gv vw dtwvg') ??? CaesarBrutus Strategy using max : (1) consider all possible answers (2) give them each a score (3) use our techniques to get max gv vw dtwvg hw wx euxwh ix xy fvyxi jy yz gwzyj kz za hxazk la ab iybal mb bc jzcbm nc cd kadcn od de lbedo pe ef mcfep qf fg ndgfq rg gh oehgr sh hi pfihs ti ij qgjit uj jk rhkju vk kl silkv wl lm tjmlw xm mn uknmx yn no vlony zo op wmpoz ap pq xnqpa bq qr yorqb cr rs zpsrc ds st aqtsd et tu brute fu uv csvuf all 26 possibilities Score for "Englishness"? up to you…

Caesar Cipher: decipher >>> decipher('gv vw dtwvg') 'od de lbedo' CaesarBrutus Strategy using max : (1) consider all possible answers (2) give them each a score (3) use our techniques with max [0, 'cr rs zpsrc'] [0, 'gv vw dtwvg'] [0, 'jy yz gwzyj'] [0, 'mb bc jzcbm'] [0, 'qf fg ndgfq'] [0, 'wl lm tjmlw'] [1, 'bq qr yorqb'] [1, 'ds st aqtsd'] [1, 'nc cd kadcn'] [1, 'vk kl silkv'] [1, 'xm mn uknmx'] [2, 'ap pq xnqpa'] [2, 'hw wx euxwh'] [2, 'ix xy fvyxi'] [2, 'kz za hxazk'] [2, 'rg gh oehgr'] [2, 'sh hi pfihs'] [2, 'uj jk rhkju'] [2, 'yn no vlony'] [3, 'fu uv csvuf'] [3, 'pe ef mcfep'] [3, 'ti ij qgjit'] [3, 'zo op wmpoz'] [4, 'et tu brute'] [4, 'la ab iybal'] [4, 'od de lbedo'] all 26 possibilities Score for "Englishness"? up to you… won't always be correct!

Caesar Cipher: decipher >>> decipher('gv vw dtwvg') 'et tu brute' CaesarBrutus [0.4680, 'jy yz gwzyj'] [0.4960, 'mb bc jzcbm'] [0.5420, 'uj jk rhkju'] [0.5567, 'ix xy fvyxi'] [0.5597, 'qf fg ndgfq'] [0.5718, 'fu uv csvuf'] [0.5753, 'bq qr yorqb'] [0.5833, 'kz za hxazk'] [0.5859, 'xm mn uknmx'] [0.5880, 'gv vw dtwvg'] [0.5902, 'vk kl silkv'] [0.6110, 'ap pq xnqpa'] [0.6304, 'zo op wmpoz'] [0.6318, 'wl lm tjmlw'] [0.6717, 'cr rs zpsrc'] [0.6735, 'hw wx euxwh'] [0.6963, 'nc cd kadcn'] [0.7153, 'ti ij qgjit'] [0.7398, 'la ab iybal'] [0.7442, 'yn no vlony'] [0.7867, 'pe ef mcfep'] [0.7880, 'sh hi pfihs'] [0.7918, 'rg gh oehgr'] [0.8213, 'ds st aqtsd'] [0.8609, 'od de lbedo'] [0.9082, 'et tu brute'] all 26 possibilities Score for "Englishness"? up to you… Strategy using max : (1) consider all possible answers (2) give them each a score (3) use our techniques to get max depends on how you score

… Caesar Cipher: encipher encipher( 'gv vw dtwvg', 0 ) encipher( 'gv vw dtwvg', 1 ) encipher( 'gv vw dtwvg', 2 ) encipher( 'gv vw dtwvg', 3 ) encipher( 'gv vw dtwvg', 4 ) encipher( 'gv vw dtwvg', 5 ) encipher( 'gv vw dtwvg', 25 ) returns 'gv vw dtwvg' 'hw wx euxwh' 'ix xy fvyxi' 'jy yz gwzyj' 'kz za hxazk' 'la ab iybal' 'fu uv csvuf' encipher( s, n ) should return the string s with each alphabetic character shifted/wrapped by n places in the alphabet Brutus won't mind if I use his salary to bring Justin Timberlake to the Colosseum next month... Historically bad decision #43:

CHR and ORD Orchard Field

CHR and ORD Chateauroux

Mutable vs. Immutable data Changeable types: dictionary Unchangeable types: list tuple string int float bool What's a dictionary? I guess I'll have to look it up! x 42 x = 42

Reference vs. Value Changeable types: dictionary Unchangeable types: list tuple string int float bool L L[0]L[1]L[2] Reference, Pointer, id L = [5,42,'hi'] x 5 42 'hi' 42 x = 42

“Pass By Value” def main() """ calls conform """ print " Welcome to Conformity, Inc. " fav = 7 conform(fav) print " My favorite number is", fav def conform(fav) """ sets input to 42 """ fav = 42 return fav 7 fav

7 “Pass By Value” def main() """ calls conform """ print " Welcome to Conformity, Inc. " fav = 7 conform(fav) print " My favorite number is", fav def conform(fav) """ sets input to 42 """ fav = 42 return fav 7 fav PASS BY VALUE “Pass by value” means that data is copied when sent to a method 42

Passing lists by value… def main() """ calls conform2 """ print " Welcome to Conformity, Inc. " fav = [ 7, 11 ] conform2(fav) print " My favorite numbers are", fav def conform2(fav) """ sets all of fav to 42 """ fav[0] = 42 fav[1] = 42 What gets passed by value here? fav L[0]L[1] 5 42 fav

Passing lists by value… def main() """ calls conform2 """ print " Welcome to Conformity, Inc. " fav = [ 7, 11 ] conform2(fav) print " My favorite numbers are", fav def conform2(fav) """ sets all of fav to 42 """ fav[0] = 42 fav[1] = 42 fav L[0]L[1] 5 42 fav can change data elsewhere! The reference is copied!

The conclusion You can change the contents of lists in functions that take those lists as input. Those changes will be visible everywhere. (actually, lists or any mutable objects) (immutable objects are safe, however)

Views of the world Engineers think their equations approximate reality.

Views of the world Engineers think their equations approximate reality. Physicists think reality approximates their equations.

Views of the world Engineers think their equations approximate reality. Physicists think reality approximates their equations. Mathematicians don't care.

Views of the world Axioms Definitions Creating structure from a few simple facts... Creating structure from a few simple actions... if/else while for arithmetic operations variables arrays ProofAlgorithm Engineers think their equations approximate reality. Physicists think reality approximates their equations. Mathematicians don't care.

Lists’ flexibility Lists can hold ANY type of data A = [ 42., 75., 70. ] float list A they don’t have to be horizontal lists!

double list A they don’t have to be horizontal lists! Lists’ flexibility Lists can hold ANY type of data A = [ 42., 75., 70. ] float list A

Lsits’ flexibility Lists can hold ANY type of data double list A int list A “go” “red” “sox!” String list A

2d lists or arrays Lists can hold ANY type of data -- including lists ! list A A = [ [1,2,3,4], [5,6], [7,8,9,10,11] ]

list A 2d arrays list A[0] A[1] A[2] Lists can hold ANY type of data -- including lists ! A = [ [1,2,3,4], [5,6], [7,8,9,10,11] ]

list A Jagged arrays list A[0] A[1] A[2] Lists can hold ANY type of data -- including lists ! A = [ [1,2,3,4], [5,6], [7,8,9,10,11] ] Rows within 2d arrays need not be the same length…

list A A[0] A[1] A[2] Lists can hold ANY type of data -- including lists ! A = [ [1,2,3,4], [5,6], [7,8,9,10,11] ] Rows within 2d arrays need not be the same length… We will not use jagged arrays at least in hw 10

Rectangular arrays list A A[0] A[1] A[2] How many rows does A have, in general ? How many columns does A have, in general ? What does each component of A[1][2] mean ? A[1][2] = 42 A[2][3] A[0][0]

Creating a 2d array def create2dArray( width, height ): """ does just that """ A = [] # start with nothing for row in range( height ): for col in range( width ): return A

Displaying a 2d array import csplot B = create2dArray( 10, 10 ) csplot.show( B ) B[1][8] = 1 # set this item to 1 csplot.show( B ) Be sure to download the newest version of this file… nearby coordinates…

Problem 2 -- “Life” Evolutionary rules Grid World Everything depends on a cell’s eight neighbors red cells are alive white cells are empty Exactly 3 neighbors give birth to a new, live cell! Exactly 2 or 3 neighbors keep an existing cell alive Any other number of neighbors kill the central cell (or keep it dead) John Conway

Problem 2 -- Life Evolutionary rules Grid World Everything depends on a cell’s eight neighbors red cells are alive white cells are empty Exactly 3 neighbors give birth to a new, live cell! Exactly 2 or 3 neighbors keep an existing cell alive Any other number of neighbors kill the central cell (or keep it dead)

Problem 2 -- Life Evolutionary rules Grid World Everything depends on a cell’s eight neighbors red cells are alive white cells are empty Exactly 3 neighbors give birth to a new, live cell! Exactly 2 or 3 neighbors keep an existing cell alive Any other number of neighbors kill the central cell (or keep it dead)

Problem 2 -- Life Evolutionary rules Grid World Everything depends on a cell’s eight neighbors red cells are alive white cells are empty Exactly 3 neighbors give birth to a new, live cell! Exactly 2 or 3 neighbors keep an existing cell alive Any other number of neighbors kill the central cell (or keep it dead) life out there... Keep going!

Problem 2 -- Creating Life B = update( B ) old generation or "board" new generation or "board"

Problem 2 -- Creating Life B = update( B ) old generation or "board" new generation or "board"

Problem 2 -- Details For each generation… 0 represents an empty cell 1 represents a living cell outermost edge should always be left empty (even if there are 3 neighbors) compute all cells based on their previous neighbors before updating any of them life out there... B = update( B ) old generation or "board" new generation or "board"

Problem 2 -- to  and beyond! Are there stable life configurations? Are there oscillating life configurations? Are there self-propagating life configurations? "rocks" "plants" "animals" period 3 period 2

Problem 2 -- to  and beyond! Are there life configurations that expand forever? What is the largest amount of the life universe that can be filled with cells? How sophisticated can the structures in the life universe be? Google for GOLLY, Game of Life Are all feasible configurations reachable?

Lab & Homework…

import sys for i in range(4): for j in range(8): sys.stdout.write('#') print software object representing the screen's standard output Without extra spaces… Output ######## method (function) that prints only its input