if not dumbTree.exists(testWord): dumbTree.put(testWord) queue.put(ParentNode(testWord, node)) sweTree = BST() dumbTree = BST() queue = LinkedQueue() sweAlpha = list("abcdefghijklmnopqrstuvwxyzåäö") with open("texts/word3.txt", "r") as wordLines: for word in wordLines: word = word.rstrip("\n") if not sweTree.exists(word): sweTree.put(word) print( "Detta program kommer att hitta vilka ord som ligger längst ifrån ditt startord." ) startWord = input("Startord:") startNode = ParentNode(startWord) dumbTree.put(startNode.value) queue.put(startNode) maxDistance = 0 words = []
from module import BST sweTree = BST() dumbTree = BST() sweAlpha = list("abcdefghijklmnopqrstuvwxyzåäö") with open("texts/word3.txt", "r") as wordLines: #Loads words into a Binary Search Tree. for word in wordLines: word = word.rstrip("\n") if not sweTree.exists(word): sweTree.put(word) print("Detta program visar alla 'barn' till ett ord") startWord = input("Faderord:") dumbTree.put(startWord) for n in range(3): #Change all the letters to all the possible. One at a time. for char in sweAlpha: testWord = list(startWord) # "str.." -> ["s","t","r",...] testWord[n] = char testWord = "".join(testWord) # ["s","t","r",...] -> "str.." if sweTree.exists(testWord): if not dumbTree.exists(testWord): print(testWord) dumbTree.put(testWord)
elif sweTree.exists(testWord): if not dumbTree.exists(testWord): dumbTree.put(testWord) queue.put(ParentNode(testWord,node)) sweTree = BST() dumbTree = BST() queue = LinkedQueue() sweAlpha = list("abcdefghijklmnopqrstuvwxyzåäö") with open("texts/word3.txt","r") as wordLines: for word in wordLines: word = word.rstrip("\n") if not sweTree.exists(word): sweTree.put(word) print("Detta program kommer hitta den snabbaste vägen mellan två trekaraktärs-ord.") startWord = input("Startord:") endWord = input("Slutord:") startNode = ParentNode(startWord) dumbTree.put(startNode.value) queue.put(startNode) while not queue.isEmpty(): node = queue.get() makeChildren(node)
from module import BST sweTree = BST() dumbTree = BST() sweAlpha = list("abcdefghijklmnopqrstuvwxyzåäö") with open("texts/word3.txt","r") as wordLines: #Loads words into a Binary Search Tree. for word in wordLines: word = word.rstrip("\n") if not sweTree.exists(word): sweTree.put(word) print("Detta program visar alla 'barn' till ett ord") startWord = input("Faderord:") dumbTree.put(startWord) for n in range(3): #Change all the letters to all the possible. One at a time. for char in sweAlpha: testWord = list(startWord) # "str.." -> ["s","t","r",...] testWord[n] = char testWord = "".join(testWord) # ["s","t","r",...] -> "str.." if sweTree.exists(testWord): if not dumbTree.exists(testWord): print(testWord) dumbTree.put(testWord)