Assignment08

.pdf

School

Indiana University, Bloomington *

*We aren’t endorsed by this school

Course

505

Subject

Computer Science

Date

Jan 9, 2024

Type

pdf

Pages

4

Uploaded by ColonelWorld13096

Report
Assignment 08 Instructions 1. Write your functions according to the signature provided below in a python(.py) file and submit them to the autograder for evaluation. 2. The autograder has a limited number of attempts. Hence, test it thoroughly before submit- ting it for evaluation. 3. Save your python file as text(.txt) file and submit it to the canvas. 4. If the assignment has theoretical questions, upload those answers as a pdf file on the canvas. 5. Submission on the canvas is mandatory and the canvas submitted text file should be the same as that of the final submission of the autograder. If not, marks will be deducted. 6. No submission on canvas or no submission on autograder then marks will be deducted. 7. Access the auto grader at https://c200.luddy.indiana.edu. Question 1 You are in charge of communications aboard a spaceship on a top-secret mission. For security reasons, mission control will send messages that have numeric values hidden within an array. You know that whenever you receive an array of numbers, the hidden number is the length of the largest subsequence such that all elements of the subsequence are exactly 7 away from at least one other element of the subsequence. Write code to automatically translate these arrays into integers. Examples Input: arr = [2,9,1] Output: 2 Explanation: the subsequence <2,9> has 2 elements that are 7 apart from each other. Thus, the answer is 2. Input: arr = [6,0,14,4,7,3] Output: 3 Explanation: the subsequence <0,14,7> has 3 elements that are 7 apart from each other. Thus, the answer is 3. Constraints: • Solve using hashing • There will be no duplicate values in the input array Function def translate_message(arr): #return int return value 1
Question 2 A blacksmith named Gary is crafting armor for the king. He received an order to make n shields of varying sizes. These orders came in an array of size n with each element of the list being a tuple of the form [a ,b]‘ where a is the height of the shield and b is the length. However, before Gary could start crafting these orders, an evil wizard cast a spell on the list so that some of the elements were duplicated and then flipped within the array. Now Gary needs to find how many symmetric pairs are within the list so that he can remove the duplicates and make the correct shields for the king. Write code that takes the list of orders and returns the size of the original list if all symmetric parts are removed. Examples Input: orders = [[1,2],[2,1]] Output: 1 Explanation: The two elements in the array are symmetric pairs to each other. So one of them must be a duplicate. If we remove it, the list will have size of 1. Input: orders = [[5,8], [3,2], [5,8]] Output: 3 Explanation: There are no symmetric pairs in the list, so there are no duplicates. Thus, the size is still 3. Constraints: • Solve using hashing Function def find_order_size(orders): #return int return order_size Question 3 On one fine day you decided to visit the circus nearby. In that circus, all the people are playing one game. In that game, you are displayed with a long string and you need to decide if that string has some repetition in it. You instantly notice that the string only has 4 unique characters in it W, X, Y, Z. Your job is to note down which strings of length 10 are repeating in the given string. Examples Input: circusString = "WWWWWXXXXXWWWWWXXXXXXWWWWWYYYZZZ" Output: ["WWWWWXXXXX", "XXXXXWWWWW"] Explanation: The given two sequences in the output array are present multiple times in the input string and have length = 10. 2
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help