0% found this document useful (0 votes)
7 views

java problem solving

The document outlines programming assignments related to Karel the Robot, including deadlines for submissions and section sign-ups. It introduces various Karel problems, such as RoombaKarel and BeeperDoublingKarel, emphasizing the goal of cleaning a grid of beepers. Additionally, it discusses algorithms as processes for solving problems, highlighting the existence of multiple algorithms for each problem with different trade-offs.

Uploaded by

marybellesuez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

java problem solving

The document outlines programming assignments related to Karel the Robot, including deadlines for submissions and section sign-ups. It introduces various Karel problems, such as RoombaKarel and BeeperDoublingKarel, emphasizing the goal of cleaning a grid of beepers. Additionally, it discusses algorithms as processes for solving problems, highlighting the existence of multiple algorithms for each problem with different trade-offs.

Uploaded by

marybellesuez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Problem-Solving with Karel

Announcements
● Programming Assignment #1 Out:
● Karel the Robot: Due Friday, January 20 at
3:15 PM
● Email: Due Sunday, January 22 at 11:59PM
● Sign up for section!
http://cs198.stanford.edu/section
Signups close this Sunday at 5PM.
Friday Four Square
● Good snacks!
● Good company!
● Good game!
● Good fun!
● Today at 4:15
in front of
Gates.

Don't be this guy!


Revisiting HurdleJumpingKarel
RowSweepingKarel
Before

1 . . . . . . . .
1 2 3 4 5 6 7 8
After

1 . . . . . . . .
1 2 3 4 5 6 7 8
Let's Code it Up!
Karel has to take six steps…

1 . . . . . . .
1 2 3 4 5 6 7

…but has to sweep seven corners.


A More Elaborate Problem
8 . . . . . . . .
7 . . . . . . . .
6 . . . . . . . .
5 . . . . . . . .
4 . . . . . . . .
3 . . . . . . . .
2 . . . . . . . .
1 . . . . . . . .
1 2 3 4 5 6 7 8
RoombaKarel
The Problem
● Setup:
● Karel begins at (1, 1).
● Karel's world has no walls in it.
● Each corner has zero or one beepers.
● Goal:
● Karel's world is free of beepers.
● Karel's location does not matter.
8 . . . . . . . .
7 . . . . . . . .
6 . . . . . . . .
5 . . . . . . . .
4 . . . . . . . .
3 . . . . . . . .
2 . . . . . . . .
1 . . . . . . . .
1 2 3 4 5 6 7 8
8 . . . . . . . .
7 . . . . . . . .
6 . . . . . . . .
5 . . . . . . . .
4 . . . . . . . .
3 . . . . . . . .
2 . . . . . . . .
1 . . . . . . . .
1 2 3 4 5 6 7 8
8 . . . . . . . .
7 . . . . . . . .
6 . . . . . . . .
5 . . . . . . . .
4 . . . . . . . .
3 . . . . . . . .
2 . . . . . . . .
1 . . . . . . . .
1 2 3 4 5 6 7 8
8 . . . . . . . .
7 . . . . . . . .
6 . . . . . . . .
5 . . . . . . . .
4 . . . . . . . .
3 . . . . . . . .
2 . . . . . . . .
1 . . . . . . . .
1 2 3 4 5 6 7 8
8 . . . . . . . .
7 . . . . . . . .
6 . . . . . . . .
5 . . . . . . . .
4 . . . . . . . .
3 . . . . . . . .
2 . . . . . . . .
1 . . . . . . . .
1 2 3 4 5 6 7 8
Algorithms
● An algorithm is a process for solving
some problem.
● Named for 9th-century Persian
mathematician ‫محمد بن موسى الخوارزمي‬,
(Muhammad ibn Musa al-Khwarizmi).
● There are many algorithms for solving
each problem; each offers tradeoffs.
8 . . . . . . . .
7 . . . . . . . .
6 . . . . . . . .
5 . . . . . . . .
4 . . . . . . . .
3 . . . . . . . .
2 . . . . . . . .
1 . . . . . . . .
1 2 3 4 5 6 7 8
BeeperDoublingKarel
Before

1 . .
137 .

1 2 3
After

1 . .
274 .

1 2 3
How do you double beepers?
1 . 3. .

1 2 3
1 . 2. 2.

1 2 3
1 . 1. 4.

1 2 3
1 . . 6.

1 2 3
1 . 6. .

1 2 3

You might also like