summaryrefslogtreecommitdiff
path: root/possible_words_before_chatgpt_optimization.py
blob: 3646b8de1bfef4fa8490b2fdfb858f6cd52d2487 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
words = open("words_235886.txt").readlines()
combinations = []
valids = []
letters = list(input())
n = len(letters)


def dfs(cur_str):
    if cur_str in combinations:
        return
    combinations.append(cur_str)
    if len(cur_str) == n:
        return
    for letter in range(n):
        if letters[letter]:
            new_str = cur_str + letters[letter]
            letters[letter] = None
            dfs(new_str)
            letters[letter] = new_str[-1]
        

dfs("")

combinations.pop(0)
for word in combinations:
    if (word + "\n") in words:
        valids.append(word)

valids = sorted(valids, key=lambda x: x[0])

for valid in valids:
    print(valid)