Uploaded by Huqawida

INFS1101-Assignment3-Updated

advertisement
INFS 1101 – Assignment 3
General Instructions

The third Assignment consists of two parts:
o Part I consists of developing algorithms and implementing them in code blocks on
Code.org.
o Part II is the coding part where you will develop algorithms and implement them
in python programs.

This is an individual assignment. Please review the Plagiarism and Academic Integrity
policy presented in the first class.
You can make multiple submissions , but only the last submission before the deadline
will be graded. Keep in mind that for each day your submission is late, a 25%
deduction from your grade will be applied.
You should submit 2 files at the completion of the assignment, a screenshot of the first
part and a zip file containing the Part 2’s requirements, both files should be called
assignment3_xxxxxxxx where you change xxxxxxxx to your student number.


Part I
Instructions
1. Sign in to your account at code.org.
2. Work through all the steps of the following block code exercises:

Exercise 20. Functions in Minecraft

Exercise 21. Functions with Harvester

Exercise 22. Functions with Artist

Exercise 24. Counting with Variables
3. Submit a screenshot of your progress on D2L Dropbox.
Part II
Instructions
Exercise 1
In a distant galaxy, an ancient civilization developed a unique method for describing stars and
planets. They encoded this information in a unique string of numbers. In this coding system, the
even indexes (0, 2, 4, ...) of the string represent the number of stars in a constellation, while the
odd indexes (1, 3, 5, ...) symbolize the number of planets. Your task is to develop a function
called CelestialDecoder that can decipher these codes and reveal the total count of stars and
planets. The function takes the decoded message as input and returns a message that contains
the total of stars and planets. The main program reads the encoded message, passes it to the
CelestialDecoder function for interpretation, and prints the returned value.
Example: For an encoded message "425125448"
Index
Encoded Message
Number of Stars:
Even
Odd
Even
Odd
Even
Odd
Even
Odd
Even
0
1
2
3
4
5
6
7
8
4 2 5 1 2 5 4 4 8
4 + 5 + 2 + 4 + 8 = 23 (using all numbers in even positions)
Number of Planets: 2 + 1 + 5 + 4
= 12 (using all numbers in odd positions)
Instructions

You will use a while loop to iterate through the string verify each digit is it is in an even
or an odd index

Calculate and display the total number of stars and planets.
Sample run 1:
Enter the constellation code string: 425125448
Total Stars: 23, Total Planets: 12
Sample run 2:
Enter the constellation code string: 7589645
Total Stars: 26, Total Planets: 18
Sample run 3:
Enter the constellation code string: 84815
Total Stars: 21, Total Planets: 5
Exercise 2
In outer space, messages sent in space are vulnerable to alteration due to cosmic conditions
and interference. To ensure the correctness of messages during transmission, messages need
to be encoded in a certain way. In this particular encoding system, characters in a message are
followed by a number which indicates how many times the character is to be repeated.
However, there's a twist: if the position of the character in the original message is odd (1, 3, 5,
...) the character is repeated one additional time, and if it's even (0, 2, 4, ...), one repetition is
subtracted. Your task is to develop a function called CommsDecoder that will take the encoded
message as input and return the decoded message to the main program. The main program will
read the encoded message, pass it to the function CommsDecoder and print the returned
value.
Example: For an encoded message "H2e3l4o5"

"H" should be repeated 2 + 1 times (due to its odd position).

"e" should be repeated 3 - 1 times (due to its even position).

"l" should be repeated 4 + 1 times (due to its odd position).

"o" should be repeated 5 - 1 times (due to its even position).
Decoded Message: HHHeellllloooo
3
2
5
4
Instructions

Use a while loop to traverse through the message character by character.

Depending on the index of the character, adjust the repeat factor and add the
repeated character.

Assume that user will always input a character followed by single digit number,
no need for input validation (or you can do it for the sake of making it more
challenging but it will not affect your grade)
Sample run 1:
Enter the encoded message to be sent into space: H3L2X7O6
Encoded Message: H3L2X7O6
Decoded Message: HHHHLXXXXXXXXOOOOO
Sample run 2:
Enter the encoded message to be sent into space: I4N5T7E5R3
Encoded Message: I4N5T7E5R3
Decoded Message: IIIIINNNNTTTTTTTTEEEERRRR
Sample run 3:
Enter the encoded message to be sent into space: S3t2E6L2L1A4R5
Encoded Message: S3T2E6L2L1A4R5
Decoded Message: SSSSTEEEEEEELLLAAARRRRRR
Exercise 3
If you have watched the movie "Interstellar," you realize how crucial it is to manage the
spaceship's fuel to navigate through the vast and unknown expanse of space. Your task, as a
budding astronaut and coder, is to create a Python function that simulates a simplified version
of this journey, where you’ll manage your spaceship's fuel while navigating through a grid. The
program will take the initial fuel and the journey path in a string format, where 'R' signifies
moving right, 'U' indicates moving up, 'L' means moving left, and 'D' represents moving down.
Your task is to develop a function called FuelManager. This function will accept the initial fuel
amount and the movement string as inputs. It will then compute the final destination
coordinates and determine the remaining fuel after the journey. In the main program, your
task is to read the initial fuel and journey path, pass these parameters to the FuelManager
function, and print the returned values.
Scenario:

Your spaceship starts at the coordinates x,y=(0, 0) in a grid-like space.

When the spaceship goes up, its y coordinates increase by 1.

When the spaceship downward, its y coordinates decrease by 1.

When the spaceship right, its x coordinates increase by 1.

When the spaceship left, its x coordinates decrease by 1.

Moving towards the right ("R") or upwards ("U") consumes 1 unit of fuel each step.

Moving left ("L") or downwards ("D") consumes no fuel at all (done via gravitational
assist of nearby planets).

The spaceship's movements are encoded in a string (e.g., "RRUULLDD").
Sample run 1:
Enter the initial fuel level: 24
Enter journey path (sequence of 'R', 'U', 'L', 'D'): RRLLUUUDDDD
Final fuel level: 19, Final position: (0, -1)
Sample run 2:
Enter the initial fuel level: 15
Enter journey path (sequence of 'R', 'U', 'L', 'D'): UUUUUUDDLRRR
Final fuel level: 6, Final position: (2, 4)
Sample run 3:
Enter the initial fuel level: 45
Enter journey path (sequence of 'R', 'U', 'L', 'D'): URRDDLLLUUDRRR
Final fuel level: 37, Final position: (2, 0)
Exercise 4
An asteroid belt is a region between the orbits of Mars and Jupiter in our solar system filled
with numerous asteroids. This region contains safe and dangerous zones. We'll use a string to
represent this area, with 'S' indicating safe zones and 'D' representing dangerous ones. Develop
a function called PathFinder. This function will take a string as input and determine the longest
consecutive sequence of safe zones. It will calculate this sequence and return it to the main
program. In the main program, you need to read the asteroid belt, pass it to the function, and
print the returned value.
Instructions

You will use a while loop to iterate through the string to check if each character is “S” or
“D”

Create variables to keep track of the current sequence length and the longest sequence
length. Initialize both to 0.

For each character, compare the current sequence length with the longest sequence
length and update the longest sequence length if necessary.

Calculate and display the length of the longest safe sequence.
Sample run 1:
Enter the asteroid belt: SSDSSSSDSD
Longest safe sequence: 4
Sample run 2:
Enter the asteroid belt: DDDSSSDSSDDDSSSSDSSSSSSSDSDS
Longest safe sequence: 7
Sample run 3:
Enter the asteroid belt: SDSDSDSDS
Longest safe sequence: 1
Download