# CS 141 Lab 5x - do 2 out of 3

## 1. A mazing problem

Ruby is lost in a maze, but, before she went in she put down a coin right outside the door (so she will know if she gets out). She starts with a wall on her right, and there are no loops, so if she keeps her hand on a wall to her right at all times while making forward progress, she can find her way out (eventually). Write a Ruby program to escape from the maze, pick up the coin, and halt. Your program must work on both maze0.rby and maze1.rby.

## 2. Lost in the woods

Ruby has gone out for a long walk in the woods (think of the walls as trees!), but, being worried about getting lost, has left a trail of bread crumbs (single coins) behind her. She left 2 coins at her starting point.

There is no coin where Ruby starts, but there is one within one block, either in front, behind, right, or left of her.

The trail will never cross itself, but sometimes Ruby forgets to drop a coin (but never more than one in a row).

Write a Ruby program to follow the trail of bread crumbs home, collect them all, face east, and halt.

#### hints

This program is not entirely trivial! Use the problem solving techiques you have learned. Here's how I would simplify the problem.
1. crumb1.rby has no gaps and no walls -- so, first do the problem with no gaps and no walls!
2. crumb2.rby has no gaps but has walls -- do this next
3. crumbWalls.rby has gaps and walls -- and finally, this

## 3. Ruby the Teller

Ruby has taken a job as a bank teller, and has to learn to stack coins in order by height.

Write a Ruby program to sort stacks of coins. Ruby starts at home. On each avenue is a stack of coins. Rearrange the coins so the biggest stack is on first avenue, second biggest on second avenue and etc.

you must preserve the various stacks (each one is a person's account balance), so if initially the stacks look like:

*
*
* *
****
the final situation would be
*
*
**
****

Your program must work on both coins.rby and coins1.rby, but!, it will not tell you success!, you must look for yourself to see if it worked correctly...