Created
October 26, 2012 21:23
-
-
Save RK11/3961640 to your computer and use it in GitHub Desktop.
All posibilities
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def all_posibilities(max_length, letters): | |
result = [] | |
for length in range(1, max_length+1): | |
pos = [0]*length | |
actual_word = "" | |
limit = (len(letters))**length | |
nbr_of_words = 0 | |
while nbr_of_words < limit: | |
for char in range(length): | |
actual_word = letters[pos[char]] + actual_word | |
result.append(actual_word) | |
actual_word = "" | |
pos[0] += 1 | |
for position in range(len(pos)): | |
if pos[position] >= len(letters): | |
pos[position] = 0 | |
try: | |
pos[position+1] +=1 | |
except IndexError: | |
break | |
nbr_of_words += 1 | |
return result | |
#print all_posibilities(4, ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment