The language is python
Write the function
largest_edge_group(vertices)
that consumes vertices, a list of list of integer containing the coordinates of the consecutive vertices of a polygon. The function largest_edge_group returns the size of the largest group of same length edges.
Your function must run in O(n), where n is the length of vertices.
Example
largest_edge_group([[0,0],[1,1],[0,2],[-2,3],[-1,2]]) => 3
Hint
Remember, it is not possible to compare Floats for strict equality,
but since the coordinates are integers, the squared distance is
too.
Restrictions
Do not import any modules other than math and check. You are always allowed to define your own helper/wrapper functions, as long as they meet the assignment restrictions. Do not use Python constructs from later modules (e.g. commands continue or break, zip, anything with set or enumerator, etc.).
Solution:
Function:
def largest_edge_group(vertices):
#list to store edge length
distance=[]
#list to store count of the edges of same length upto the point of time
len_count=[]
for i in range(len(vertices)-1):
# **2 is to find square, and square root is not taken for strict equality
dist=((vertices[i][0]-vertices[i+1][0])**2)+((vertices[i][1]-vertices[i+1][1])**2)
distance.append(dist)
len_count.append(distance.count(dist))
return max(len_count)
Output while running the program in python shell:
The language is python Write the function largest_edge_group(vertices) that consumes vertices, a list of list of...
Python question It is required to make a function biggest_vert_group(vert) that consumes vert, which is a list of list of integers containing the coordinates of the consecutive vertices of a polygon. The function should return the size of the largest group of same length edges. This function must have a big-o runtime of O(n) where n is the length of vert Example biggest_vert_group([[0,0],[1,1],[0,2],[-2,3],[-1,2]]) => 3 only library allowed to be imported is math. list comprehensions, sets and/or enumerators are Forbidden...
with python Write a function called linear_search which consumes a sorted list of integers and a number and linearly searches for the number in the list. Your function should return how many comparisons were made in order to find the element in the list. If the element is not in the list, your linear search should return -1 For example:
language is python Write a function named subsetStrings that has two inputs, a list of strings and an integer n. Your function should use a single list comprehension to create a new list containing the first n characters of each string in the input list if the length of the individual string is at least n (strings that are too short should be skipped). Your function should return the new list ex: inputList 'Frederic, 'powerade', 'spring break, 'pen'] and n-4...
USING PYTHON 3 Write a function no_pairs(L) that consumes a list of natural numbers L and mutates it, replacing any natural numbers which appear exactly twice in the list with -1. The no_pairs function returns None. This function should run in at worst O(n log n) time. HINT: Solving this problem within the demanded runtime will likely require both O(n log n) sorting and O(log n) searching! Samples: L = [254 , 955 , 198 , 590 , 368] after...
solve with python Write a recursive function recStringWithLenCount() that takes a one-dimensional list of strings as a parameter and returns the count of strings that have at least the length of second parameter passed into the function that are found in the list. Recall that you can determine whether an item is a string by writing type(item) == str. The only list functions you are allowed to use are len(), indexing (lst[i] for an integer i), or slicing (lst[i:j] for...