|
|
|
Week 2, 9/4
Prelab Exercises
- Complete problems 1-6 from this week's in-class questions. Bring written
answers 2 & 5 with you to lab. Submit Sqrt.java,
Gambler.java, and Birthday.java
using assignment name plab02.
- Reading
- Chapter 1 in Sedgewick & Wayne
- Supplemental Reading from JavaBat
Lab Exercises
- Snarf lab02.
From the In-Class Questions:
- Adapted from Problem 1.4.31 from Sedgewick & Wayne: A drunkard begins walking
aimlessly, starting at a lamp post. At each time step, the drunkard
forgets where he or she is, and takes one step at random, either north,
east, south, or west, with probability 25%. How far will the drunkard be
from the lamp post after N steps?
Write a program RandomWalker.java that takes an integer, N, as
input from the user and
simulates the motion of a random walker for N steps. After each step, print
the location of the random walker, treating the lamp post as the origin (0,
0). Also, print the square of the distance from the origin.
- Modify SelfAvoidingWalk to calculate and print the average
length of the paths as well as the dead-end probability. Keep separate
the average lengths of escape paths and dead-end paths.
- Modify SelfAvoidingWalk to read in the world configuration
from a file. The first line has N, the size of
the square lattice. The rest of the lines have a
'-' if the space is open and a 'X' if
there is an obstacle at that space. The
walker begins in at (x/2,y/2) or
(4,4) - or where the O is in the example
below. In the data files, there will be no marker for the
starting position.
8
--------
-XX--XX-
-------X
-------X
XX--O---
X-------
--XXX---
---X--XX
Calculate the probability of
escape and dead-end paths in world1.txt, world2.txt,
and world3.txt.
- Extra credit: Display the worlds using the princeton.StdDraw class.
- Why is the following quotation true?
A drunk man will find his way home, but a drunk bird may get lost
forever
- Shizuo Kakutani
Submitting
Submit RandomWalker.java, SelfAvoidingWalk.java, and
README.txt. You should submit a README for every assignment in
this class that, at minimum, includes:
- Collaborators: any people that you
consulted in completing the assignment
- Resources Used: any books, notes, webpages (other than course
webpages) that you used consulted while completing the assignment
- Time Spent: estimate of how many hours you spent on the assignment
- Comments: any comments or you have on the assignment
Your README will often contain assignment-specific answers as well. For
this lab, your README should include:
- The average distance from the origin for the RandomWalker after
N steps where you have tried different values for N.
- the probability of escape and
dead-end paths that you calculated for world1.txt, world2.txt, and world3.txt.
Due: Submit the lab before class on Monday for credit under
assignment name lab02.
|