def makeChildren(node): for n in range(3): for char in sweAlpha: testWord = list(node.value) testWord[n] = char testWord = "".join(testWord) if 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 att hitta vilka ord som ligger längst ifrån ditt startord." )
for char in sweAlpha: testWord = list(node.value) testWord[n] = char testWord = "".join(testWord) if testWord == endWord: print("En väg hittad mellan " + startWord + " och " + testWord) writeChain(ParentNode(testWord,node)) sys.exit() 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:")
for char in sweAlpha: testWord = list(word) testWord[n] = char testWord = "".join(testWord) if testWord == endWord: print("Det finns en väg till " + endWord + ".") sys.exit() elif sweTree.exists(testWord): if not dumbTree.exists(testWord): dumbTree.put(testWord) queue.put(testWord) 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 avgör om det finns en väg från startord till slutord som går via korrekta ord" ) startWord = input("Startord:") endWord = input("Slutord:")
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)
for n in range(3): for char in sweAlpha: testWord = list(word) testWord[n] = char testWord = "".join(testWord) if testWord == endWord: print("Det finns en väg till " + endWord +".") sys.exit() elif sweTree.exists(testWord): if not dumbTree.exists(testWord): dumbTree.put(testWord) queue.put(testWord) 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 avgör om det finns en väg från startord till slutord som går via korrekta ord") startWord = input("Startord:") endWord = input("Slutord:")
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)