PHPackages                             daniel-ac-martin/word-ladder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. daniel-ac-martin/word-ladder

ActiveProject[CLI &amp; Console](/categories/cli)

daniel-ac-martin/word-ladder
============================

A command-line program and library for solving word ladder puzzles.

0.1(11y ago)1211GNU GPLPHP

Since May 18Pushed 11y ago1 watchersCompare

[ Source](https://github.com/daniel-ac-martin/word-ladder)[ Packagist](https://packagist.org/packages/daniel-ac-martin/word-ladder)[ Docs](https://github.com/daniel-ac-martin/word-ladder)[ RSS](/packages/daniel-ac-martin-word-ladder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

word-ladder
===========

[](#word-ladder)

word-ladder is a command-line program and PHP library for solving [word ladder puzzles](http://en.wikipedia.org/wiki/Word_ladder).

*Word ladder* is a word game invented by [Lewis Caroll](http://en.wikipedia.org/wiki/Lewis_Carroll). The player is given two words and must find a 'ladder' from one to another on which only one letter is changed between words on adjacent rungs on the ladder. e.g.

```
Ladder from GIT to HUB:
GIT -> GUT -> HUT -> HUB

```

Word ladder problems can have more than one correct answer. Because of this, word-ladder will declare the first solution it finds, then it will analyse all solutions (the same length as the first one) and declare the *best* one. (Where 'best' is defined as being the solution whose least common word, is more common than all other solutions' least common words. i.e. Ladders are judged to only be as strong as their weakest link / rung.)

There are some variations on the word ladder game in which the problem must be solved in a specified number of steps. In some cases it is possible to solve the problem in fewer steps. Unlike most other solvers, word-ladder accepts an option to attempt to solve the problem in a set number of steps. (When this option is not provided it simply attempts to solve the problem in as few steps as possible.)

Program - Getting started
-------------------------

[](#program---getting-started)

Download [the Phar](https://github.com/daniel-ac-martin/word-ladder/releases/download/0.1/word-ladder.phar). Place it wherever you want on your system. Execute it from the command line through PHP. (Or you can execute it directly if you have a valid, modern PHP binary at /usr/bin/php.)

Program - Usage
---------------

[](#program---usage)

```
Usage: word-ladder.phar START FINISH [STEPS]

```

The command-line program accepts three parameters, *START*, *FINISH*, and *STEPS*, where only the third, *STEPS* is optional.

**START**: The first word in the ladder.

**FINISH**: The last word in the ladder.

**STEPS**: The number of steps / rungs on the ladder.

Example:

```
$ php word-ladder.phar git hub
Attempting: git -> hub
First solution set (3 steps) found after 2 lookups:
0: git  [a person who is deemed to be despicable or contemptible; "only a ro...]
1: gib  [a castrated tomcat]
2: gub  []
3: hub  [the central part of a car wheel (or fan or propeller etc) through w...]
[Prevalence score: 112.26878713664]
Finding and analysing all solutions... Done.

10 solution(s) found.

0: git  [a person who is deemed to be despicable or contemptible; "only a ro...]
1: gut  [a strong cord made from the intestines of sheep and used in surgery]
2: hut  [small crude shelter used as a dwelling]
3: hub  [the central part of a car wheel (or fan or propeller etc) through w...]

[Prevalence score: 16551.249116398]

```

Library - Getting started
-------------------------

[](#library---getting-started)

1. Get [Composer](http://getcomposer.org)
2. Require word-ladder with `php composer.phar require daniel-ac-martin/word-ladder`
3. Install dependencies with `php composer.phar install`

Library - Usage
---------------

[](#library---usage)

The library is invoked by including Composer's autoloader and then calling the method, *WordLadder\\WordLadder::solve*. Please see the following example.

```
