Welcome (back) to IST 338 ! Wow I see the resemblance Average of - - PowerPoint PPT Presentation

welcome back to ist 338
SMART_READER_LITE
LIVE PREVIEW

Welcome (back) to IST 338 ! Wow I see the resemblance Average of - - PowerPoint PPT Presentation

Welcome (back) to IST 338 ! Wow I see the resemblance Average of these two? Problem 0: Already complete! Problem 1: Four-fours program: Can be done for lab... Homework 0 Problem 2: Rock-paper-scissors


slide-1
SLIDE 1

Welcome (back) to IST 338 !

  • Homework 0
  • due Sun. night (11:59pm)

Wow – I see the resemblance

Problem 0: Already complete! Problem 1: Four-fours program: Can be done for lab... Problem 2: Rock-paper-scissors program (Maybe done already!) Problems 3-5: Picobot! empty room (3) maze (4) + extra (5) Problem 6: Reading + response…

Average of these two?

slide-2
SLIDE 2

Welcome (back) to IST 338 !

  • Homework 0
  • due Sun. night (11:59pm)

Picobot!

Wow – I see the resemblance

Problem 0: Already complete! Problem 1: Four-fours program: Can be done for lab... Problem 2: Rock-paper-scissors program (Maybe done already!) Problems 3-5: Picobot! empty room (3) maze (4) + extra (5) Problem 6: Reading + response…

slide-3
SLIDE 3

Welcome back (from) Baltimore!

world's expert on badge- based incentive systems for education…

slide-4
SLIDE 4

Extreme RPS!?

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

slide-5
SLIDE 5

Last time…

CS != Programming

slide-6
SLIDE 6

What about the Python programming language ?

slide-7
SLIDE 7

One possible relationship... vs.

Python ?

slide-8
SLIDE 8

Happy co-existence… It can even be comfy!

Python !

One possible relationship... vs.

slide-9
SLIDE 9

Exclusive Choices

if perc > .95: print 'A' elif perc > .90: print 'A-' elif perc > .70: print 'Pass' else: print 'Aargh!'

if ... elif ... else When using if . elif … . else at most one block will run: the first whose test is True. If all fail, the else will run

4 mutually exclusive blocks

elif and else are optional

in a single control structure

slide-10
SLIDE 10

What's the difference?

if perc > .95: print 'A' elif perc > .90: print 'A-' elif perc > .70: print 'Pass' if perc > .95: print 'A' if perc > .90: print 'A-' if perc > .70: print 'Pass' mutually exclusive blocks nonexclusive blocks

How many separate control structures does each side have? What if perc == .99 ? (How would we set it?)

slide-11
SLIDE 11

comp = 'rock' user = 'paper' if comp == 'paper' and user == 'paper': print 'We tie. Try again?' elif comp == 'rock': if user == 'scissors': print 'I win! *_*' else: print 'You win. Aargh!'

Does this program print the correct RPS result this time? Does it always? # of BLOCKS ? # of TESTS ? # of Control Structures ?

What will this do?

try it: RPS example #1

slide-12
SLIDE 12

comp = 'rock' user = 'rock' if comp == 'rock': if user == 'paper': print 'I win *_*!' elif user == 'scissors': print 'You win.' else: print 'Tie.' print 'Ties go to the runner.' print ' - and I am running!'

# of BLOCKS # of TESTS Counting...

... what if the else were indented?

Printing…

try it: RPS example #2

slide-13
SLIDE 13

How many possible “input cases” are there?

comp = 'rock' user = 'rock' if comp == 'rock': print 'I win *_*!' if user == 'paper': print 'You win.' else: print 'An awful tie'

For how many is this program correct?

What does this print?

try it: RPS example #3

slide-14
SLIDE 14

How many possible “input cases” are there?

comp = 'rock' user = 'rock' if comp == 'rock': print 'I win *_*!' if user == 'paper': print 'You win.' else: print 'An awful tie'

For how many is this program correct?

What does this print?

… how efficiently can RPS be represented by program?

  • Fewest number of blocks?
  • Fewest number of tests?

'rock' 'paper' 'scissors' 'rock' 'paper'

'scissors'

comp user

slide-15
SLIDE 15

This week: hw0pr1

get Python running on your own machine shell or command- line or terminal

(the execution environment)

Python source code, a plain-text file

(here, edited by the Sublime text editor)

shell prompt > or $ Python prompt >>>

slide-16
SLIDE 16

Commanding the command-line

in Windows' plain cmd

Mac/Linux/Windows Powershell pwd ls mkdir mv cp cd .. .

dir move copy mkdir . . . cd cd .

print working directory (current path) list (current directory) change directory

shortcut for "directory above" shortcut for "current directory"

move (source/from) (destination/to) copy (source/from) (destination/to) make directory (name of new dir)

slide-17
SLIDE 17

Mental model .. .

CS5

(folder) (file)

pico3.txt pico4.txt

(file)

Desktop

CS5

(folder) start

usual picture ~ a window into the underlying structure

slide-18
SLIDE 18

a couple of shortcuts… Up arrow

  • Down arrow ~ scrolls the other way

Tab key

  • Brings back previously-typed commands
  • Cycles through possibilities (older versions would pause…)
  • Completes the file or folder name you start
slide-19
SLIDE 19

Mental model .. .

CS5

(folder) (file)

pico3.txt pico4.txt

(file)

$ mkdir BotFiles $ cd B $ cp ../pico3.txt . $ mv p .. $ cd ..

Desktop

CS5

(folder)

$ pwd $ ls $ cd C

dir copy move

$

start

cd

slide-20
SLIDE 20

Mental model .. .

CS5

(folder)

pico4.txt

(file)

$ mkdir BotFiles $ cd B $ cp ../pico3.txt . $ mv p .. $ cd ..

Desktop

CS5

(folder)

$ pwd $ ls $ cd C

dir copy move

$

end

cd .

BotFiles

(folder)

BotFiles

(folder) (file)

pico3.txt

(file)

pico3.txt

slide-21
SLIDE 21

Try it!

CS5

(folder)

hw0pr0.py

(file)

$ mkdir Week0 $ cd .. $ mv ../h .

Desktop

CS5

(folder)

$ cd W

move

$

start

hw0pr1.py

(file)

$ mkdir Week1 $ cp ../h .

copy

$ cd W $ $

Extra #2: What line here would copy the hw0pr0.py file to the current location? See if you can use tabs… Extra #1: What is the current folder here?

Draw the changes these shell commands will make…

slide-22
SLIDE 22

Not to mention…

ping find . curl or wget which python cat

where type may need to install add ;c:\python27 This is a window into the directory tree… if you don't want to type the full path: c:\python27\python tree

slide-23
SLIDE 23

XKCD's perspective…

slide-24
SLIDE 24

Command line?!?

The Operating System's Window Manager Computational interactions (files, folders, data…) Physical interactions (arithmetic and storage)

Consume Compose Crazy!

not really fair…

slide-25
SLIDE 25

Command line?!?

The Operating System's Window Manager Computational interactions (files, folders, data…) Physical interactions (arithmetic and storage)

Consume Compose

Commoditized!

slide-26
SLIDE 26

Useful?

Consuming Composing

slide-27
SLIDE 27

Useful?

Everything at the command line is automatable and programmable… Consuming Composing

slide-28
SLIDE 28

Useful!

Everything at the command line is automatable and programmable… Consuming Composing

slide-29
SLIDE 29

you'll see 100% in the next 10 minutes

Another language already?

Special-purpose language

you might see 50% by the end

  • f the term

Python Picobot

General-purpose language

The Picobot simulator

www.cs.hmc.edu/picobot

Picobot!

even then, <1% of its libraries!

slide-30
SLIDE 30

Picobot area already covered Picobot can't tell… area not covered (yet!)

Inspiration?

walls

Goal: full-room coverage with only local sensing…

HW problems 3 and 4: Picobot!

slide-31
SLIDE 31

Picobot area already covered Picobot can't tell… area not covered (yet!)

Roomba!

walls

HW problems 3 and 4: Picobot!

can't tell "vacuumed" from "unvacuumed" area

Goal: full-room coverage with only local sensing…

slide-32
SLIDE 32

Surroundings

Picobot can only sense things directly to the N, E, W, and S For example, here its surroundings are N E W S

NxWx

N E W S

Surroundings are always in NEWS order.

slide-33
SLIDE 33

What are these surroundings?

NxWx

N E W S

Surroundings are always in NEWS order.

Wow - this one is disgusting!

slide-34
SLIDE 34

How many distinct surroundings are there? N E W S

Surroundings

slide-35
SLIDE 35

How many distinct surroundings are there? N E W S

xxxx Nxxx xExx xxWx xxxS NExx NxWx NxxS xEWx xExS xxWS NEWx NExS NxWS xEWS NEWS

(won’ ’ ’ ’t happen)

== 16 possible 24

Surroundings

slide-36
SLIDE 36

State

Picobot's memory is a single number, called its state. State is the internal context of a computation, i.e., the subtask.

State and surroundings represent everything Picobot knows about the world

Picobot always starts in state 0.

I am in state 0. My surroundings are xxWS.

self-contained but not simplistic

slide-37
SLIDE 37

Rules

Picobot acts through a set of rules: state

I am in state 0. My surroundings are xxWS.

surroundings xxWS N direction new state Picobot checks its rules from the top each time. When it finds a matching rule, that rule runs. Notes

slide-38
SLIDE 38

Rules

Each rule expresses your intent for Picobot! state

I am in state 0. My surroundings are xxWS.

surroundings xxWS N direction new state If I'm now in state 0 seeing xxWS, Then I move North, and "change" to state 0. Picobot acts through a set of rules

slide-39
SLIDE 39

Wildcards

Asterisks * are wild cards. They match walls or empty space:

x***

N state surroundings direction new state EWS may be wall or empty space N must be empty I only care about NORTH being EMPTY

slide-40
SLIDE 40

state surroundings direction new state

(A) A rule that sends Picobot to the North as far as it can go: (B) What does this next rule do? (C) What about this one? (D) How could we stop at the bottom and return up through the same column?

x*** N

  • >

N*** 1 W

  • >

1 ***x 1 S

  • >
slide-41
SLIDE 41

The Rule: One step per rule

How many times does rule (A) run? ___________________ How many times does rule (B) run? ___________________ How many times does rule (C) run? ___________________

Extra! What additional rules would be needed in order to ensure that Picobot fully explores the empty room (not this crazy room) from any starting spot? (this is problem 3…)

How many times does rule (D) run? ___________________

One rule to rule them all? Precious!

Try it!

Where does Picobot stop? Why?

Picobot's world

P

slide-42
SLIDE 42

problem 3

Picobot hw problems

problem 4 Extra! (#5) Your rules must work regardless of Picobot's starting position… !

slide-43
SLIDE 43

problem 3

Picobot's revenge!

problem 4 Extra! (#5) Your rules must work regardless of Picobot's starting position… !

slide-44
SLIDE 44

Be Picobot!

"Run" this Picobot program:

state surr dir newstate

***x S

  • >

*x*S E

  • >

*E*S X 1

  • >

(1) How many times does the 1st rule run? _________ (2) How many times does the 2nd rule run? _________ (3) How many times does the 3rd rule run? _________ 1st rule 2nd rule 3rd rule (6) Add 2-3 rules that will, in state 1, get Picobot to the top of the stalagmite, then stop. (4) In English, what does state 0 do? (Extra!) What approach could get Picobot to travel around the whole outer edge? (5) How could this help clear the empty room? … just a thought experiment

P

top of stalagmite

A more intricate picobot world

slide-45
SLIDE 45

Maze strategies?

slide-46
SLIDE 46
slide-47
SLIDE 47

Maze strategies? Right Hand Rule

Why might this be difficult for Picobot?

slide-48
SLIDE 48

Maze strategies? Right Hand Rule

We'll need to use state to represent the direction Picobot is facing.

State 0 State 1 State 2 State 3

facing

slide-49
SLIDE 49

Suppose Picobot wants to traverse a maze with its right hand always on the wall. We use state 0 to represent that “Picobot is facing North” (A) Here is a single rule that tells Picobot: If you're facing N with a wall at right and space ahead then go forward” (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!” (C) (for HW) Write 1 or 2 rules to tell Picobot to do the right thing if it hits a dead end. (A) (B) (C) Repeat this IDEA for all four states, representing all four facing directions.

xE** N

  • >
  • >
slide-50
SLIDE 50

Problem 6 this week…

Typically an article on CS or an application... Submit a one-paragraph response

A few sentences that raise or address questions, using the article as a guide.

Small part (5 pts)

5 – insightful, careful 4 – thoughtful 3 – complete, on topic 0-2 – less than complete

This week's article might not seem like CS at first…

slide-51
SLIDE 51

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

  • ver 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!

slide-52
SLIDE 52

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

  • ver 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!

slide-53
SLIDE 53

problem 3

CS ~ complexity science

problem 4 Extra! (5)

Shortest Picobot program:

6 rules

Shortest Picobot program:

8 rules

Shortest Picobot program:

? rules

complexity is deeper than simply the # of rules…

slide-54
SLIDE 54

You are not alone!

Tutoring hours all weekend in the LAC lab - also, weekday evenings @ LAC lab, too

I can attest to that! Lead on! I will follow.

As you head northwards…

slide-55
SLIDE 55

Each week's lab…

1) … to work on the problems 2) Also, you can use the CS5 lab and tutoring times, linked from the site 0) Feel free to stay for the final hour…

Encouraged: bring your laptop

slide-56
SLIDE 56

Seek help!

Tutoring schedule…

this link:

every day there are tutoring hours in the LAC computer lab

Linde Activities Center

slide-57
SLIDE 57

HMC office + tutoring locations

Beckman B163 ~ office location Enter through Olin building Tutoring hours are in the Linde Activities Center computer lab (LAC lab) west-side entrance

slide-58
SLIDE 58

Each week's lab…

1) … to work on the problems 2) Also, you can use the CS5 lab and tutoring times, linked from the site 0) Feel free to stay for the final hour…

Encouraged: bring your laptop

slide-59
SLIDE 59
slide-60
SLIDE 60