An open API service indexing awesome lists of open source software.

https://github.com/danielkummer/kata_word_chains

Code kata about building word chains
https://github.com/danielkummer/kata_word_chains

Last synced: 11 months ago
JSON representation

Code kata about building word chains

Awesome Lists containing this project

README

          

# Code kata - word chains

See [the official kata page](http://codekata.com/kata/kata19-word-chains/)

# Exercise

Write a program that solves word-chain puzzles. There’s a type of puzzle where the challenge is to build a chain of words, starting with one particular word and ending with another. Successive entries in the chain must all be real words, and each can differ from the previous word by just one letter. For example, you can get from “cat” to “dog” using the following chain.

1. cat
2. cot
3. cog
4. dog

The objective of this kata is to write a program that accepts start and end words and, using words from the dictionary, builds a word chain between them. For added programming fun, return the shortest word chain that solves each puzzle. For example, you can turn “lead” into “gold” in four steps (lead, load, goad, gold), and “ruby” into “code” in six steps (ruby, rubs, robs, rods, rode, code).
Once your code works, try timing it. Does it take less than a second for the above examples given a decent-sized word list? And is the timing the same forwards and backwards (so “lead” into “gold” takes the same time as “gold” into “lead”)?

# My solution

Install by running

bundle install

Program args:

Usage: word_chains.rb [options] [file]
Mandatory options:
-s, --start START_WORD Enter a start word
-e, --stop STOP_WORD Enter a stop word
-v, --verbose Verbose output
-h, --help Display this screen
If no file is supplied it detects based on wordlist.txt