Last active
April 22, 2020 00:28
-
-
Save ildyria/666910d37bada6a100ef20451b3b7ebd to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env python3 | |
| def load_words(): | |
| with open('words_alpha.txt') as word_file: | |
| valid_words = word_file.read().split() | |
| return valid_words | |
| def contains(a:list, b:list): | |
| # print(a) | |
| # print(b) | |
| if not a: | |
| return True, b | |
| else: | |
| e = a.pop(0) | |
| if e in b: | |
| bb = list(b) | |
| bb.remove(e) | |
| return contains(a, bb) | |
| else: | |
| return False, [] | |
| def clean_dic(dictio, letters): | |
| updated_dic = [] | |
| for w in dictio: | |
| save = False | |
| t = w.upper() | |
| for l in letters: | |
| save |= (l in t) | |
| if save: | |
| updated_dic.append(w) | |
| return updated_dic | |
| anagram_list = list('DEZOONHEETGIELLRAAMDROP') | |
| anagram_list.sort() | |
| # anagram_list = list('MAGICIANS') | |
| # anagram_list.sort() | |
| english_words = load_words() | |
| simpler_english = clean_dic(english_words, anagram_list) | |
| simpler_english.sort(key=len,reverse=True) | |
| # print(len(english_words)) | |
| # print(len(simpler_english)) | |
| # string_2 = list('MAGIC') | |
| # print(contains(string_2, anagram_list)) | |
| # print(anagram_list) | |
| def gen_word_list(wl, anagram): | |
| if not anagram: | |
| print(wl) | |
| elif len(anagram) < 6: | |
| print(wl, anagram) | |
| else: | |
| for w in simpler_english: | |
| if len(w) < 3: | |
| continue | |
| candidate = list(w.upper()) | |
| aanagram = list(anagram) | |
| if len(anagram) < len(candidate): | |
| continue | |
| wl_copy = list(wl) | |
| yes, anagram_copy = contains(candidate, aanagram) | |
| if yes: | |
| wl_copy.append(w) | |
| gen_word_list(wl_copy, anagram_copy) | |
| else: | |
| continue | |
| gen_word_list([], anagram_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment