Given: A positive integer n≤7 .
Return: The total number of permutations of lengthn , followed by a list of all such
permutations (in any order).
copy.deepcopy() rules!
Return: The total number of permutations of length
copy.deepcopy() rules!
import copy n = int(input()) listn = list(range(1, n+1)) results = [] for i in range(1, n+1): results.append([i]) for position in range(1, n): new_results = [] for result in results: new_listn = [x for x in listn if x not in result] for element in new_listn: new_result = copy.deepcopy(result) new_result.append(element) new_results.append(new_result) results = new_results print(len(new_results))
print(new_results)
Комментариев нет:
Отправить комментарий