word chaining puzzle | Sololearn: Learn to code for FREE!

word chaining puzzle

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. cat cot cog dog The objective 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).

11th Sep 2018, 8:07 PM
pooria nikzad
pooria nikzad - avatar
2 Answers
+ 2
Here's an idea how it could be done. Unfortunately, it only works if there's exactly one way to go from word a word to word b https://code.sololearn.com/cWp2sDNu33hN/?ref=app /Edit: Here's a better working version: https://code.sololearn.com/cj684hjlsmpy/?ref=app
12th Sep 2018, 7:00 AM
Anna - avatar
Please provide a link to your Code Playground code so we can help you troubleshoot the specific issues you are running into. The Code Playground should be relatively easy to find in the website version of SoloLearn, but if you are in the app version, it can be accessed via the curly braces, green circle with plus sign to add a new project, then select the project type. Looking forward.
12th Sep 2018, 3:21 AM
Janning⭐ - avatar