I know that this is a trivial problem, but I’m having a hard time
solving it with tuby. I could use a little extra help with my
programming in ruby skills.
The problem I’m faced to solving (taken from a puzzle in a newspaper)
is a series of alphabetical triplets like:
Combining a letter from each triplet, you can form words which will
form a sentence (in the above case: ‘ugly duckling’).
What I want to do is go through all possible permutations of
characters, in the triplets, and crossreference them with a dictionary
to create all possible permutations of words in a sentence. I’ve put
the above triplets into an array of arrays: [[“ubc”, “deg”, “lap”,
“pyq”], [“ved”, “run”, “pac”, “ken”, “alm”, “mli”, “rnt”, “alg”]]. Now
here’s my problem. How do I recurse the words in the best way? What I
want to do is start to check “udlp”, “udly”, “udlq”, then “udap”,
“uday”, “udaq” and so on? I know it’s a computer practise to have a
function call itself. Is that needed here? Because I’m running into a
problem having nested loops, because the words are of variable length.
Any ideas on this?