1 / 129

Extreme RPS in IST 380!

Extreme RPS in IST 380!. They call that an alien?. Spock mind-melds three-eyed aliens!. Provably. http://www.youtube.com/watch?v=iapcKVn7DdY http://www.youtube.com/watch?v=yuEZEyDdmvQ. Today in IST380. Homework 0 due Wed. @ 11:59pm!. practice program, RPS(LS), Picobot , part 1.

kalkin
Télécharger la présentation

Extreme RPS in IST 380!

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ExtremeRPSin IST 380! They call that an alien? Spock mind-melds three-eyed aliens! Provably. http://www.youtube.com/watch?v=iapcKVn7DdY http://www.youtube.com/watch?v=yuEZEyDdmvQ

  2. Today in IST380 Homework 0 due Wed. @ 11:59pm! practice program, RPS(LS), Picobot, part 1 Schedule reminders Picobot maze-solver: extra-credit Homework 1 due 2/12 @ 11:59pm No class on Mon., 2/23 (travel…) CS today: its two fundamental building blocks… Data! Functions!!

  3. Piazza for all/any concerns/questions public: post to whole class A great forum for course questions and answers…

  4. Piazza you'll get a welcome email… to IST 380 @ Harvey Mudd sign-in + choose your message frequency

  5. Piazza for all CS5 concerns/questions individual concerns or your source code / bugs? In-person + pair programming are better strategies for bugs. But we'll try to take a look… private: post to instructors Need an account for the CS machines? for the submission site? Piazza us!

  6. Picobot!?

  7. Piqued by Picobot? for some, it's real…

  8. for others, it's the ONLY reality! Seventy years ago, in 1940, a popular science magazine published a short article that set in motion one of the trendiest intellectual fads of the 20th century. At first glance, there seemed little about the article to augur its subsequent celebrity. Neither the title, “Science and Linguistics,” nor the magazine, M.I.T.’s Technology Review, was most people’s idea of glamour. And the author, a chemical engineer who worked for an insurance company and moonlighted as an anthropology lecturer at Yale University, was an unlikely candidate for international superstardom. And yet Benjamin Lee Whorf let loose an alluring idea about language’s power over the mind, and his stirring prose seduced a whole generation into believing that our mother tongue restricts what we are able to think. and I thought my language was alien!

  9. Seventy years ago, in 1940, a popular science magazine published a short article that set in motion one of the trendiest intellectual fads of the 20th century. At first glance, there seemed little about the article to augur its subsequent celebrity. Neither the title, “Science and Linguistics,” nor the magazine, M.I.T.’s Technology Review, was most people’s idea of glamour. And the author, a chemical engineer who worked for an insurance company and moonlighted as an anthropology lecturer at Yale University, was an unlikely candidate for international superstardom. And yet Benjamin Lee Whorf let loose an alluring idea about language’s power over the mind, and his stirring prose seduced a whole generation into believing that our mother tongue restricts what we are able to think. and I thought my language was alien!

  10. Maze? RightHand Rule

  11. Maze strategies? RightHand Rule facing Keep your "right hand" on the wall, Picobot! State 0 State 1 State 2 State 3 We'll need to use state to represent the direction Picobot is facing.

  12. We use state 0 to represent that “Picobot is facing North” Suppose Picobotwants to traverse a maze with its right hand always on the wall. (A) Here is a single rule that tells Picobot: If you're facing N using the RHR with space ahead then go forward” 0 xE** N 0 -> (A) 0 (B) Let's write a single rule that tells Picobot: “If you're facing North and lose the wall, then get over to the wall now!” 0 0 -> (B) (C) (for HW) Write 1 or 2 rules to tell Picobot to do the right thing if it hits a dead end. (C) 0 Repeat this IDEA for all four states, representing all four facing directions.

  13. What about the Pythonprogramming language ?

  14. Python ? One possibility...

  15. Python ! One possibility... Happy co-existence… It can even be comfy!

  16. The foreign language of python… syntax semantics intent How it looks What it does What it should do name = raw_input('Hi... what is your name?') print# prints a blank line if name == 'Eliot' orname == 'Ran': print'I\'m "offline." Try later.' elif name == 'Zach': # is it Zach? print'Zach Quinto...?', 'No?', 'Oh.' else: # in all other cases... print'Welcome', name, '!' my_choice = random.choice( [ 'R','P','S' ] ) print'My favorite object is', my_choice, "!" This program should greet its user appropriately.

  17. The foreign language of python… syntax semantics intent How it looks What it does What it should do name = raw_input('Hi... what is your name?') print# prints a blank line if name == 'Eliot' orname == 'Ran': print'I\'m "offline." Try later.' elif name == 'Zach': # is it Zach? print'Zach Quinto...?', 'No?', 'Oh.' else: # in all other cases... print'Welcome', name, '!' my_choice = random.choice( [ 'R','P','S' ] ) print'My favorite object is', my_choice, "!"

  18. graphical view of a program's semantics 'Zach' ‘Eliot’ or ‘Ran’ Zach Eliot or Ran 'Chris' Chris Zach What about me?

  19. The foreign language of python… syntax semantics intent How it looks What it does What it should do www.theonion.com How Python looks! • how punctuation is used • the language keywordsused • use of whitespace • peculiarities of formatting • how behavior is affected …

  20. Python Syntax! (1) What Python syntax errors can you find here? (2) This line is doing three things… what are they? import random user = raw_input( "Choose your weapon! " ) comp = random.choice( ['rock','paper','scissors") ] print'user (you) chose:', 'user' print'comp (me!) chose:' comp ifuser == rockandcomp = 'paper' print'The result is, YOU LOSE!' print'unless you're a CS 5 grader, then YOU WIN!' (3) How many different uses of punctuation can you find?

  21. Python's syntax? (1) Find and correct any errors... ! (2) This line is doing three things… what are they? import random (1) prints the "weapon" prompt (2) gets user's input from the kbd (3) assigns that input to the variable user set-equals always uses ONE equals sign user = raw_input( "Choose your weapon! ") comp = random.choice( ['rock','paper','scissors'] ) print'user (you) chose:', user print'comp (me!) chose:', comp every block of code must line up! match brackets and quotes ! The comma prints a space and does NOT go to the next line. test-equals uses TWO equals signs ifuser == rockandcomp == 'paper': print'The result is, YOU LOSE!' print'unless you\'re a CS 5 grader, then YOU WIN!' a colon starts a new block every block of code must line up! flattering - or flouting - graders is encouraged! a backslash handles special characters (3) See how many different uses of punctuation you can find.

  22. Data, data everywhere… Data

  23. Data, data everywhere… 1 Zettabyte 1.8 ZB 8.0 ZB 800 EB logarithmic scale Data produced each year 161 EB 5 EB 1 Exabyte 100-years of HD video + audio 60 PB 1 Petabyte Human brain's capacity 14 PB 2002 2006 2009 2011 2015 1 Petabyte == 1000 TB 1 TB = 1000 GB References (2015) 8 ZB: http://www.emc.com/collateral/analyst-reports/idc-extracting-value-from-chaos-ar.pdf (2002) 5 EB: http://www2.sims.berkeley.edu/research/projects/how-much-info-2003/execsum.htm (2011) 1.8 ZB: http://www.emc.com/leadership/programs/digital-universe.htm (life in video) 60 PB: in 4320p resolution, extrapolated from 16MB for 1:21 of 640x480 video (w/sound) – almost certainly a gross overestimate, as sleep can be compressed significantly! (2009) 800 EB: http://www.emc.com/collateral/analyst-reports/idc-digital-universe-are-you-ready.pdf (2006) 161 EB: http://www.emc.com/collateral/analyst-reports/expanding-digital-idc-white-paper.pdf (brain) 14 PB: http://www.quora.com/Neuroscience-1/How-much-data-can-the-human-brain-store

  24. Big Data?

  25. 'debt' more-than-average searches for debt: sell fewer-than-average searches for debt: buy

  26. 'fun' 'water'

  27. If you torture the data enough, it will confess. - R. Coates

  28. Data's elevation? wisdom G.G.M, et al. knowledge G. Garcia Marquez Google's users information Google data

  29. True False Python's data types Name Example What is it? values with a fractional part float 3.14 long 10**100 integers > 2147483647 int 42 integers <= 2147483647 the results from a comparison: bool ==, !=, <, >, <=, >= "Boolean value" Hey - someone can't spelle ! George Boole

  30. Datatypes ~ genes… What will these results be? Dominant 1.0 / 5 float 10**100 - 10**100 long int 1 / 5 41 + True bool Recessive

  31. Operate! ( ) ** - * % / + - > == < =

  32. O-per-ate! ( ) ** - * % / + - > == < =

  33. Python operators higher precedence ( ) parens ** power - negate * % / times, mod, divide + - add, subtract > == < compare = assign It's not worth remembering all these %+/* things! I’d recommend parentheses over precedence.

  34. % the mod operator 7 % 3 9 % 3 8 % 3 16 % 7 x%y returns the remainder when x is divided by y x%2 == 0 x%2 == 1 For what values of x are these True? x%4 == 0 What happens on these years? x%4 == 3

  35. the "equals" operators = != == This is true – but what is it saying!?

  36. the "equals" operators = != == SET equals isn't equal to TEST equals I want ===!

  37. Try it! how = works x = 41 y = x + 1 z = x + y Run these lines x y z extra! What are the values of x, y, and z here? a = 11/2 b = a%3 c = b** a+b *a Then run this x = x + y x y z What are the values of x, y, and z here? What are the values of a, b, and c here?

  38. Inside the machine… x = 41 y = x + 1 What's happening in python: What is happening behind the scenes: Computation Data Storage 42 41 name: y type:int LOC:324 name: x type:int LOC:312 memory location 312 memory location 324 variables ~ boxes id, del

  39. Memory! Random Access Memory 41 83 105 42 name: x type: int LOC:312 name: z type: int LOC:336 name: a type: int LOC:348 name: y type: int LOC:324 a big list of boxes, each with a name, type, location, and value 512 MB of memory on or off bit= 1 "bucket" of charge Wow! Who knew they make memory out of wicker? byte= 8 bits

  40. = names data extra! a = 11/2 b = a%3 c = b** a+b *a x = 41 y = x + 1 z = x + y x y z What are the values of a, b, and c here? I see differences on the left and right – and with an eye to spare! x = x + y x y z

  41. Are numbers enough? Yes and no… You need listsof numbers, as well! and strings- lists of characters - too. Both of these are Python sequences…

  42. string functions str(42) returns'42' converts input to a string len('42') returns 2 returns the string’s length 'XL' +'II' returns 'XLII' concatenatesstrings 'VI' * 7 returns 'VIVIVIVIVIVIVI' repeatsstrings composing strings using + and *

  43. string functions str(42) returns'42' converts input to a string len('42') returns 2 returns the string’s length 'XL' +'II' returns 'XLII' concatenatesstrings 'VI' * 7 returns 'VIVIVIVIVIVIVI' repeatsstrings s1 = 'ha' Given these strings s2 = 't' s1 + s2 What are 2*s1 + s2 + 2*(s1+s2) What did you say!?!

  44. Data ~ digin! s = 'harvey' 0 1 2 3 4 5 s[2] 'r' indexing is index s[2:4] 'rv' is slicing s[::-1] 'yevrah' is

  45. Indexing uses [ ] s = 'harvey mudd college' 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 index Read as "s-of-zero" or "s-zero" s[0] is s[6] is s[ ] 'e' is

  46. In a negative mood ? Python's there for you ! Negative indices… 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 s = 'harveymudd college' -19 -17 -15 -13 -11 -9 -7 -5 -3 -1 -18 -16 -14 -12 -10 -8 -6 -4 -2 Negative indices count backwards from the end! s[-1] is s[-2] is s[-0] is

  47. Slicing s = 'harvey mudd college' 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 s[ : ] slices the string, returning a substring What's going on here? s[0:6] 'harvey' is s[12:18] 'colleg' is s[17:] 'ge' is s[:] is 'harvey mudd college'

  48. Slicing s = 'harvey mudd college' 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 s[ : ] slices the string, returning a substring second index is ONE AFTER the last character a missing index means that end of the string first index is the first character s[0:6] 'harvey' is s[12:18] 'colleg' is s[17:] 'ge' is s[:] is 'harvey mudd college'

  49. Slicing s = 'harvey mudd college' 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 s[15:-1] is What are these slices? s[:2] is 'mud' is and these? 'e' is Don't'wor' 'e'- Be'hap' 'e' !

More Related