Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Extend the function to num_permutation (n, k=None) which takes in an additional optional keyword argument k, and returns the INTEGER number of k -permutations

 


Unfortunately, there is not much improvement. Nevertheless, we can efficiently compute the number of k-permutations based onExercise (Challenge) Extend the function num_permutation_sequence(n) so that calling send() method causes the generator to inExercise: Create a decorator to eliminate duplicate input positional arguments instead of the ouput, i.e., permutation(1,1,2)  
 
 

Extend the function to num_permutation (n, k=None) which takes in an additional optional keyword argument k, and returns the INTEGER number of k -permutations of n items. The number is given by the formula Osk Unfortunately, there is not much improvement. Nevertheless, we can efficiently compute the number of k-permutations based on the previously computed number of k 1-permutations: For k from 0 ton, Pat-1 if k>0 Pn.k = nx (n 1) x ...x (n k + 1). (6) k terms in the product. Exercise Use the yield statement to write the function num_permutation_sequence(n) that returns a generator of Pnk with k from 0 to n. In [ ]: - def num_permutation_sequence (n): output = 1 for k in range (0, n + 1) : # YOUR CODE HERE executed in 3ms, finished 12:00:19 2020-10-25 In [ ]: # tests executed in 201ms, finished 12:00:19 2020-10-25 Exercise (Challenge) Extend the function num_permutation_sequence(n) so that calling send (0) method causes the generator to increment n instead of k for the next number to generate. .e., for 0 < k < n, send(0) ... Pnk-1 Pk P+1.k Pr+1,k+1 ... (7) where without labels is the normal transition without calling the send method. Hint: n+1 Pn+1,k = Pn.k X (8) n-k +1 In [ ]: def num_permutation_sequence (n): # YOUR CODE HERE raise NotImplementedError() executed in 14ms, finished 12:00:19 2020-10-25 In [ ]: # tests executed in 20ms, finished 12:00:19 2020-10-25 Exercise: Create a decorator to eliminate duplicate input positional arguments instead of the ouput, i.e., permutation (1,1,2) will return the same result as permutation(1,2). In [ ]: - def deduplicate_input (f): ''Takes in a function f that takes a variable number of arguments possibly with duplicates, returns a decorator that remove duplicates in the positional argument.''' @functools.wraps (f) def wrapper(*args, **kwargs): # YOUR CODE HERE raise NotImplementedError() return wrapper executed in 9ms, finished 12:00:19 2020-10-25 In [ 1: # tests executed in 12ms, finished 12:00:24 2020-10-25

Step by Step Solution

3.50 Rating (170 Votes )

There are 3 Steps involved in it

Step: 1

Solution is here def numper... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Investments Analysis and Management

Authors: Charles P. Jones

12th edition

978-1118475904, 1118475909, 1118363299, 978-1118363294

More Books

Students also viewed these Mathematics questions

Question

In Problem find f (x) and simplify. f(x) = (3x + 2)(4x - 5)

Answered: 1 week ago

Question

licensure as a psychologist in the respective jurisdiction; and

Answered: 1 week ago