Last active
May 22, 2020 20:38
-
-
Save mrdmnd/3b21da2ee0b4f4a6bf2f0d660dea4c97 to your computer and use it in GitHub Desktop.
Word Chain Homework Exercise
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
import sys | |
# Should return a set() of all words in the scrabble dictionary passed in at the given file path. | |
# You should implement this file loader. | |
def LoadWords(scrabble_dictionary_path): | |
pass | |
# Return a set() of ALL valid words from the input set `all_words` that differ by exactly one letter from `word` | |
# Hint: you may want to try using regular expressions here. | |
def FindAllNeighbors(word, all_words): | |
pass | |
# Use breadth first search to identify a path of legal words that link `input_word` and `target_word`. | |
# This function should return the words from the chain in a list. | |
def Chain(input_word, target_word, all_words): | |
pass | |
# FUN EXTENSION! | |
# Search for the pair of words S and T with the longest "shortest path" between them - which words are really hard to navigate between? | |
# Called from command line like "wordchain.py path_to_scrabble_dict.txt" | |
if __name__ == '__main__': | |
scrabble_dict_path = sys.argv[1] | |
all_words = LoadWords(scrabble_dict_path) | |
print(Chain("TAP", "TOP", all_words)) # Should print ["TAP", "TOP"] as these words are already separated by only one edit. | |
print(Chain("CAP", "TOP", all_words)) # Could print ["CAP", "TAP", "TOP"], or any other valid sequence of words between these two. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment