welcome (back) to ist 338dodds/ist338/slides/lec2_15_ist... · 2015. 1. 29. · get python running...
TRANSCRIPT
Welcome (back) to IST 338 !
Wally
Homework 0
Alien
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?
Welcome (back) to IST 338 !
Wally
Homework 0
Alien
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…
Welcome
back (from)
Baltimore!
world's expert on badge-
based incentive systems
for education…
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
Last time…
CS != Programming
What about the Python
programming language ?
One possible relationship... vs.
Python ?
Happy co-existence…
It can even be comfy!
Python !
One possible relationship... vs.
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
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?)
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
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
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
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
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 >>>
Commanding the command-line
in Windows'
plain cmdMac/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)
Mental model .. .
CS5 (folder)
(file)pico3.txt
pico4.txt (file)
Desktop
CS5 (folder)
start
usual picture ~ a window into the underlying structure
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
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
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
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…
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
XKCD's
perspective…
Command line?!?
The Operating System's Window Manager
Computational interactions (files, folders, data…)
Physical interactions (arithmetic and storage)
Consume
Compose
Crazy!not really fair…
Command line?!?
The Operating System's Window Manager
Computational interactions (files, folders, data…)
Physical interactions (arithmetic and storage)
Consume
Compose
Commoditized!
Useful? Consuming Composing
Useful?
Everything at the command line is
automatable and programmable…
Consuming Composing
Useful!
Everything at the command line is
automatable and programmable…
Consuming Composing
you'll see 100% in
the next 10 minutes
Another language already?
Special-purpose language
you might see
50% by the end
of the term
Python
Picobot
General-purpose language
The Picobot simulatorwww.cs.hmc.edu/picobot
Picobot!
even then, <1% of its libraries!
Picobot
area
already
covered
Picobot
can't tell…
area not
covered
(yet!)
Inspiration?
wallsGoal: full-room
coverage with only
local sensing…
HW problems 3 and 4: Picobot!
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…
Surroundings
Picobot can only sense things
directly to the N, E, W, and S
For example, here its surroundings are
N
EW
S
NxWxN E W S
Surroundings are
always in NEWS order.
What are these surroundings?
NxWx
N E W S
Surroundings are
always in NEWS order.
Wow - this one is
disgusting!
How many distinct
surroundings are there?N
EW
S
Surroundings
How many distinct
surroundings are there?N
EW
S
xxxx Nxxx xExx xxWx xxxS NExx NxWx NxxS
xEWx xExS xxWS NEWx NExS NxWS xEWS NEWS(won’’’’t happen)
== 16 possible24
Surroundings
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.
0
self-contained
but not simplistic
Rules
Picobot acts through a set of rules:
state
I am in state 0.
My surroundings
are xxWS.
surroundings
0 xxWS 0N
direction new state
Picobot checks its rules from the top each time.
When it finds a matching rule, that rule runs.Notes
Rules
Each rule expresses your intent for Picobot!
state
I am in state 0.
My surroundings
are xxWS.
surroundings
0 xxWS 0N
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
Wildcards
Asterisks * are wild cards.
They match walls or empty space:
0 x*** 0N
state surroundings direction new state
EWS may be wall or empty spaceN must be empty
I only care about NORTH being EMPTY
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?
0 x*** 0N->
0 N*** 1W->
1 ***x 1S->
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
problem 3
Picobot hw problems
problem 4 Extra! (#5)
Your rules must work regardless of
Picobot's starting position… !
problem 3
Picobot's revenge!
problem 4 Extra! (#5)
Your rules must work regardless of
Picobot's starting position… !
Be Picobot!
"Run" this Picobot program:
state surr dir newstate
0 ***x S 0->
0 *x*S E 0->
0 *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 sta
lagm
ite
A more intricate picobot world
Maze strategies?
Maze strategies? Right Hand Rule
Why might this
be difficult for
Picobot?
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
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”
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
(C) (for HW) Write 1 or 2 rules to tell Picobot to do the right thing if it hits a dead end.
0
(A)
(B)
(C) Repeat this IDEA for all four states, representing all four facing directions.
0 xE** 0N->
0 ->
Problem 6 this week…
Typically an article on CS or an application...
Submit a one-paragraph responseA 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…
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!
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!
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…
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…
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
Seek help!Tutoring schedule…
this link:
every day there are tutoring hours in the LAC computer lab Linde Activities Center
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
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