Skip to content

Compute the shortest path between two four-letter words, where two words are adjacent if they differ by a single letter.

Notifications You must be signed in to change notification settings

alexrutar/wordpath

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wordpath

Find the shortest path between two four letter words, where two words are considered adjacent if one can be obtained from the other by changing a single letter.

Installation

Simply clone the repository and build using make:

git clone https://github.com/alexrutar/wordpath
cd wordpath && make

This will probably work with most mildly modern versions of gcc.

Basic usage

The main subcommand search determines the distance between words. For example, to find the distance between the words "real" and "fake", run:

$ ./wordpath search real fake
real
heal
hell
hall
hale
hake
fake

If there is no path, the program returns an error:

$ ./wordpath search good evil
There is no path from "good" to "evil".
(return code 1)

Other Functions

Get the adjacent words in the word list:

$ ./wordpath adjacent soup
coup
soap
soul
sour

Get a word which has maximum distance from the given word:

$ ./wordpath farthest soup
axle

Get the isolated vertices (words with no neighbours):

$ ./wordpath isolated
afro
agog
ague
...
zori
zuni

Get the words which are the maximum (finite) distance apart (this is very slow):

$ ./wordpath diameter
...
Max distance 16, from "abut" to "inca".

Customizing the word dictionary

The dictionary used is the file four.txt which is extracted from the word list from the Project Gutenburg Website. Note that this program will work with any word list - the words do not need to have exactly four letters. Feel free to modify this source if there are words you do not agree with, or even use your own text source. If you do make changes, ensure that you first delete the object file graph.

The text file must be sorted alphabetically for the program to work.

About

Compute the shortest path between two four-letter words, where two words are adjacent if they differ by a single letter.

Resources

Stars

Watchers

Forks