Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. def passphraseGenerator(words,k):
  2. result = powerSet(words)
  3. result.remove([])
  4. for combo in result:
  5. if len(combo) > k:
  6. result.remove(combo)
  7. newResult = []
  8. for combo in result:
  9. perms = permutations(combo)
  10. for perm in perms:
  11. if perm not in newResult:
  12. newResult.append(''.join(perm))
  13.  
  14.  
  15. return newResult
  16.  
  17. def powerSet(l):
  18. if len(l) == 0:
  19. return [[]]
  20. else:
  21. result = []
  22. for subSet in powerSet(l[1:]):
  23. result += [subSet]
  24. result += [[l[0]] + subSet]
  25. return result
  26. def permutations(l):
  27. if len(l) == 0:
  28. return [[]]
  29. else:
  30. result = []
  31. for subPerm in permutations(l[1:]):
  32. for i in range(len(subPerm) + 1):
  33. result += [subPerm[0:i] + [l[0]] + subPerm[i:]]
  34. return result
  35.  
  36. def solve(words, k, l):
  37. pass
  38. # print(permutations([1,2,3]))
  39.  
  40. print(passphraseGenerator(["apple", "orange", "pear", "hello"], 3))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement