As a beginner need help, how to implement logic to figure out this problems. I am trying to find Permutation is a list of all arrangements of elements and Powerset is a list of all subsets of elements including the empty set.
from functools import cmp_to_key
class E1_recursion:
numbers = [9, 4, 8, 10, 2, 4, 8, 3, 14, 4, 8] #[4, 12, 3, 8, 17, 12, 1, 3, 8, 7]
def perm(self, _numbers) -> list:
return []
def pset(self, _numbers) -> list:
return []
run_choices = [
1, # Permutation
2, # Powerset
]
# Ignore this code that loads solution from file, if exists.
# The solution is not distributed.
try:
_from, _import = 'E1_recursion_sol', 'E1_recursion'
E1_recursion = getattr(__import__(_from, fromlist=[_import]), _import)
#
except ImportError:
pass
if __name__ == '__main__':
run_choices = E1_recursion.run_choices
numbers = [9, 4, 8, 10, 2, 4, 8, 3, 14, 4, 8]
n1 = E1_recursion(numbers)
# Permutation
if 1 in run_choices:
lst = [1, 2, 3]
perm = n1.perm(lst)
print(f'perm({lst}) -> {perm}')
# Powerset
if 2 in run_choices:
lst = [1, 2, 3]
pset = n1.pset(lst)
print(f'\npset({lst}) -> {pset}')
lst = n1.numbers
Output context
perm([1, 2, 3]) -> [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
pset([1, 2, 3]) -> [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]