diff options
author | Albert Tan <s22505@ykpaoschool.cn> | 2023-04-13 20:44:27 +0800 |
---|---|---|
committer | Albert Tan <s22505@ykpaoschool.cn> | 2023-04-13 20:44:27 +0800 |
commit | eff525fd045ca87652b757d247588306802975dd (patch) | |
tree | 474a88f49515ef73566ac0c930778646938b1e6b /possible_words_before_chatgpt_optimization.py | |
download | albertscripts-eff525fd045ca87652b757d247588306802975dd.tar.gz albertscripts-eff525fd045ca87652b757d247588306802975dd.zip |
Squish Albert
Diffstat (limited to 'possible_words_before_chatgpt_optimization.py')
-rw-r--r-- | possible_words_before_chatgpt_optimization.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/possible_words_before_chatgpt_optimization.py b/possible_words_before_chatgpt_optimization.py new file mode 100644 index 0000000..3646b8d --- /dev/null +++ b/possible_words_before_chatgpt_optimization.py @@ -0,0 +1,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) |