Make a network of words that differ by one letter. Try making networks for different classes of words (e.g. words beginning with “w” instead of “q”):
Note: this will take a long time if your class of words is big.
This creates a list of words that are going to be in the network, here consisting of “q” followed by 3 letters:
We’re naming this list words.
Now we construct a function that finds nearest words:
We can apply this function to any word in the list, saying we want all words that differ by at most 1 letter:
Use Rest to keep only the “rest” of the list, dropping the first element (which is here the original word):
To find the whole network, we need to apply this to every word in the list:
The # and & set up a pure function, which is then mapped over the original list of words.
To form the actual network, we need to “thread” these connections. Thread turns a connection to a list into a list of connections—for example:
Thread the nearest connections:
Then flatten out all the sublists:
Now we can turn this into a graph, or network: