From: "David A. Black" Date: 2005-11-14T23:43:18+09:00 Subject: Re: Recursive functions Hi -- On Mon, 14 Nov 2005, hans.sjunnesson@gmail.com wrote: > 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: > > ubc > deg > lap > pyq > > ved > run > pac > ken > alm > mli > rnt > alg > > 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? Several years ago I wrote a Boggle program in Ruby (actually networked Boggle), which did something similar. I don't remember exactly what I did, and I'm afraid I don't have time to remind myself and comment on it, but I can send it to you if you're interested. David -- David A. Black dblack@wobblini.net