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_quick_output.py | |
download | albertscripts-eff525fd045ca87652b757d247588306802975dd.tar.gz albertscripts-eff525fd045ca87652b757d247588306802975dd.zip |
Squish Albert
Diffstat (limited to 'possible_words_quick_output.py')
-rw-r--r-- | possible_words_quick_output.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/possible_words_quick_output.py b/possible_words_quick_output.py new file mode 100644 index 0000000..05ce3ef --- /dev/null +++ b/possible_words_quick_output.py @@ -0,0 +1,27 @@ +words = open("words_235886.txt").readlines() +visited = [] +letters = list(input()) +n = len(letters) + + +def check(cur_str): + visited.append(cur_str) + if (cur_str + "\n") in words: + print(cur_str) + + +def dfs(cur_str): + if cur_str in visited: + return + check(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("") |