Duke CS Logo CompSci 100e: Program Design & Analysis II
(Fall 2009)
Home
Course Information
Calendar
Resources
Assignments
APT problems
Lab
Lab 1 - 08/28
Lab 2 - 09/04
Lab 3 - 09/11
Lab 4 - 09/18
Lab 5 - 09/25
Lab 6 - 10/02
Lab 7 - 10/09
Lab 8 - 10/16
Lab 9 - 10/23
Lab 10 - 10/30
Lab 11 - 11/06
Lab 12 - 11/13
Lab 13 - 11/20
Lab 14 - 12/04
Help sessions
Discussion Forum
Blackboard
Oasis

Week 2, 9/4


Prelab Exercises

  1. 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.
  2. Reading
    1. Chapter 1 in Sedgewick & Wayne
    2. Supplemental Reading from JavaBat

Lab Exercises

  1. Snarf lab02.
      From the In-Class Questions:
    1. 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.

      
      
      
      
      
      
      
    2. 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.
    3. 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.
    4. Extra credit: Display the worlds using the princeton.StdDraw class.
    5. 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:
    1. Collaborators: any people that you consulted in completing the assignment
    2. Resources Used: any books, notes, webpages (other than course webpages) that you used consulted while completing the assignment
    3. Time Spent: estimate of how many hours you spent on the assignment
    4. 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:
    1. The average distance from the origin for the RandomWalker after N steps where you have tried different values for N.
    2. 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.

Last updated Fri Dec 04 11:33:58 EST 2009