Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Generate all 4096 permutations of "happy new year" in Python 3
sentence = 'happynewyear'
n = len(sentence)
total_perms = 2 ** n
for perm in range(total_perms):
generated = []
for i in range(n):
ch = sentence[i]
if (1 << i) & perm: # see explanation:
ch = ch.upper()
result = ''.join(generated)
print('{} {} {}'.format(result[:5], result[5:8], result[8:]))

This comment has been minimized.

Copy link
Owner Author

@off99555 off99555 commented Jan 4, 2017

The sentence can be changed but you will also have to change the last line (print statement) to reflect your segmentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment