Skip to content

Details

We're kicking off this month with a couple of short lightening talks from a couple of quality local software engineers:

• Richard Gibson - Akka Streams

• John Ervine - Clojure core.async

Then brush off your favourite programming language and get stuck in to a functional programming coding Kata exercise.

#########################

# This Months Kata: Word Ladder #

#########################

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 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.

-> http://codekata.com/kata/kata19-word-chains/

Solution Hint: Queues & Stacks

“Get the starting word and search through the dictionary to find all words that are one letter different. Create stacks for each of these words, containing the starting word (pushed first) and the word that is one letter different. Enqueue each of these stacks into a queue. This will create a queue of stacks! Then dequeue the first item (which is a stack) from the queue, look at its top word and compare it with the ending word. If they equal, you are done - this stack contains the ladder. Otherwise, you find all the words one letter different from it. For each of these new words create a deep copy of the stack and push each word onto the stack. Then enqueue those stacks to the queue. And so on. You terminate the process when you reach the ending word or the queue is empty." - source (http://www.cs.cmu.edu/~adamchik/15-121/labs/HW-4%20Word%20Ladder/lab.html)

Solution Hint: Graphs and Breath First Search

http://interactivepython.org/runestone/static/pythonds/Graphs/graphbfs.html (solution in python, but good overview of this type of approach).

Members are also interested in