Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def passphraseGenerator(words,k):
- result = powerSet(words)
- result.remove([])
- for combo in result:
- if len(combo) > k:
- result.remove(combo)
- newResult = []
- for combo in result:
- perms = permutations(combo)
- for perm in perms:
- if perm not in newResult:
- newResult.append(''.join(perm))
- return newResult
- def powerSet(l):
- if len(l) == 0:
- return [[]]
- else:
- result = []
- for subSet in powerSet(l[1:]):
- result += [subSet]
- result += [[l[0]] + subSet]
- return result
- def permutations(l):
- if len(l) == 0:
- return [[]]
- else:
- result = []
- for subPerm in permutations(l[1:]):
- for i in range(len(subPerm) + 1):
- result += [subPerm[0:i] + [l[0]] + subPerm[i:]]
- return result
- def solve(words, k, l):
- pass
- # print(permutations([1,2,3]))
- print(passphraseGenerator(["apple", "orange", "pear", "hello"], 3))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement