Question

In: Computer Science

You must write functions permute(...) and permuteAux(...) by analogy with the the functions enumerate(....) and enumAux(....)....

You must write functions permute(...) and permuteAux(...) by analogy with the the functions enumerate(....) and enumAux(....). Basically, the changes are to implement the "without replacement" condition: you must keep track of which letters have been used using a Boolean list in previous stages of the recursion (e.g., B[0] will be true if at an earlier stage of the recursion, 'A' has already been inserted into X; simply don't do the recursive call if that letter has been used).

Print out the sequences for permute(4,3)

CODE FOR enumerate and enumAux


letter = [chr(i) for i in range(ord('A'),ord('Z')+1)] =

def enumerate(N,L):
X = [0] * L
enumAux(N,X,0)
  
def enumAux(N,X,I):
if(I >= len(X)):
print(X)
else:
for j in range(N):
X[I] = letter[j]
enumAux(N,X,I+1)
  
enumerate(3,2)

OUTPUT:

['A', 'A']
['A', 'B']
['A', 'C']
['B', 'A']
['B', 'B']
['B', 'C']
['C', 'A']
['C', 'B']
['C', 'C']

Solutions

Expert Solution

Program screenshot:

Output:

Code to copy:

letter = [chr(i) for i in range(ord('A'),ord('Z')+1)]
#function enumerate()
def enumerate(N,L):
   X = [0] * L
   B = [0] * 26
   enumAux(N,X,B,0)

#function enumAux()
def enumAux(N,X,B,I):
    if(I >= len(X)):
        print(X)
    else:
        for j in range(N):
            if not B[j]:
                X[I] = letter[j]
                B[j] = 1
                enumAux(N,X,B,I+1)
                B[j] = 0


Related Solutions

You must write each of the following scheme functions. You must use only basic scheme functions...
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. Write a function (merge-sorter L1) that takes list-of-integers L1 and returns all elements of L1 in sorted order. You must use a merge-sort technique that, in the recursive case, a) splits L1 into two approximately-equal-length lists, b) sorts those lists, and then c) merges the...
You must write each of the following scheme functions. You must use only basic scheme functions...
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. This problem need to use DrRacket software. Racket Language. Write a function named (forget-n L1 N) that returns the elements of L1 except for the first N. If N is negative, return all elements. If N exceeds the length of L1 return the empty list....
You must write each of the following scheme functions. You must use only basic scheme functions...
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. This problem needs to use DrRacket software. Racket Language. Write a function (indices L1 X) that takes a list of elements L1 and an element X. The function returns a list of the indices in L1 that contain X. See the following examples for clarification....
You must write each of the following scheme functions. You must use only basic scheme functions,...
You must write each of the following scheme functions. You must use only basic scheme functions, do not use third-party libraries to support any of your work. Do not use any function with side effects. This problem need to use DrRacket software. Racket Language. Write a function named (first-n L1 N) that returns the first N elements of L1. If N is negative, return the empty list. If N exceeds the length of L1 return all elements of L1. (first-n...
You must write each of the following scheme functions. You must use only basic scheme functions...
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. This problem need to use DrRacket software. Racket Language. Write a function (join-together L1 L2) that takes a sorted list (ascending) of integers L1 and a sorted list of elements L2 and returns a sorted list containing all elements of both L1 and L2. See...
You must write each of the following scheme functions. You must use only basic scheme functions...
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. Write a function (indices L1 X) that takes a list of elements L1 and an element X. The function returns a list of the indices in L1 that contain X. See the following examples for clarificaton. (indices '(a b c a e f a) 'a')...
You must write each of the following scheme functions. You must use only basic scheme functions...
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. Write a function named (list-replace ALIST SYM VAL) that accepts a list of elements and returns that list where all SYM's (a single symbol) have been replaced by the VAL (some scheme value). The replacement must occur even within nested lists. For example: (list-replace '(a...
For this problem you must write the functions in a recursive manner (i.e. the function must...
For this problem you must write the functions in a recursive manner (i.e. the function must call itself) – it is not acceptable to submit an iterative solution to these problems. A. Complete the recursive function gcd(m, n) that calculate the greatest common denominator of two numbers with the following rules: # If m = n, it returns n # If m < n, it returns gcd(m, n-m) # If m > n, it returns gcd(m-n, n) # def gcd(m,n):...
You will need to write a library of functions that uses pointers. Your functions must follow...
You will need to write a library of functions that uses pointers. Your functions must follow the headers below. int intDivide(int numerator, int denominator, int *quo_ptr, int *rem_ptr); Create a function to do integer division that gives the division result and remainder via output parameters, quo_optr and rem_ptr.   Additionally, the function must return an int representing the success/failure of the function. The function should return 0 if it succeeds and -1 if there is a divide by zero error. (Note...
Enumerate 5 items that you must maintain update in the maintaining surgical supplies
Enumerate 5 items that you must maintain update in the maintaining surgical supplies
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT