0% found this document useful (0 votes)
68 views11 pages

CS101 Lecture Notes

CS101 Intro to Programming in Python Lecture Notes

Uploaded by

nxsaomsk
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)
68 views11 pages

CS101 Lecture Notes

CS101 Intro to Programming in Python Lecture Notes

Uploaded by

nxsaomsk
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

CS101 Homework #1

Hubo Plus

Read the homework description carefully and follow the instructions below. Please be fully
aware that this homework is an individual task; you could discuss the problem with your
friends, but you are not allowed to implement solutions with the help of your friends.
Note that you will fail the entire course (that is, your CS101 grade will be an F) if you
are found to be involved in any attempt of plagiarism.

Preliminaries

The cs1robots library used in Lab 1-3 is used. Specifically, you may need to use the
following methods:
drop_beeper()
pick_beeper()
on_beeper()
carries_beepers()
move()
turn_left()
load_world()
front_is_clear()
left_is_clear()
right_is_clear()
Requirements

Task 1. (5 points)

You can use your codes in Labs/Homeworks.


No point will be given if you use exit() and quit()

When you submit, wait until Grading is done is printed.

In this task, a one-way straight robot world is given (see examples below). hubo is
created at (1, 1) facing east. hubo moves by repeating the following rules in order:
1. Pick up all beepers at the current location.
2. Drop one beeper and move east once. Repeat until all beepers are consumed.
2-1. When hubo cannot move forward blocked by a wall, drops all beepers hubo carrying
and terminates.
3. terminates if there is no beeper at the current location.
Write a function task1() that makes hubo move according to the above rules. The
width of the world (number of avenues) is given from 2 to 99.
Caution: Beepers in positions where Hubot passes in the middle of the moves
should not be picked up.
Note: The last location of the Hubo and the number of beepers in the world are
checked for scoring
Example 1

input

[Link]

output
Example 2

input

[Link]

output

The beepers at (2,1) and (6,1) are not picked up.

Example 3

input

[Link]

output

The beepers at (3,1) are not picked up.


Task 2. (15 points)

You can use your codes in Labs/Homeworks.


No point will be given if you use exit() and quit()

When you submit, wait until Grading is done is printed.

The Hubo move rules are similar to those of Task 1, but the world size is given in
2 X 2 to 99 X 99.

Write a function task2() that makes hubo move in zigzags according to the move
rules. The first move of hubo must face east.

Modified hubo move rules for zigzigs

1. Pick up all beepers at the current location.


2. Drop one beeper and move once following zigzags. Repeat until all beepers are
consumed.
2-1. When hubo cannot move blocked by a wall, drop all beepers hubo carrying and
terminates.
3. terminates if there is no beeper at the current location. Go to the rule 1 if there are
beepers.
Caution: Beepers in positions where Hubot passes in the middle of the moves
should not be picked up.
Note: The last location of the Hubo and the number of beepers in the world are
checked for scoring.
Example 1

input

[Link]
output

Example 2

input

[Link]
output

Example 3

input

[Link]
output
Task 3. (5 points)

You can use your codes in Labs/Homeworks.


No point will be given if you use exit() and quit()

When you submit, wait until Grading is done is printed.


The Hubo move rules are similar to those of Task 2, but the given world is where
a previous hubo, prev_hubo has already visited.
Write a function task3() that place the hubo at the last position of prev_hubo.

hubo move rules for zigzigs

1. Pick up all beepers at the current location.


2. Drop one beeper and move once following zigzags. Repeat until all beepers are
consumed.
2-1. When hubo cannot move blocked by a wall, drop all beepers hubo carrying and
terminates.
3. terminates if there is no beeper at the current location. Go to the rule 1 if there are
beepers.
Note: Only the last location of the hubo is chekced in the grader. The number of
beepers are not checked (beepers are free to pick up and drop)
Example 1

input

[Link]
output

Example 2

input

[Link]
output

Example 3

input

[Link]
output

You might also like