in reply to Another word puzzle with too many permutations

How about a recursive solution where you stop when you can no longer apply the remaining alphabet to the search space? That way you don't try all combinations, but only those that have a potential of succeeding.

# pseudocode sub find_some ( @choices, @alphabet ) { $results = []; for $choice ( @choices ) { if ( choice_is_in_alphabet ) { @new_choices = @choices - $choice; @new_alphabet = @alphabet - letters_in( $choice ); push @$results, [ $choice, find_some( @new_choices, @new_a +lphabet ) ]; } } return $results; }

You will be left with a spanning tree of all good solutions. With a stack you could also remove the recursion.

Update: Scope error

Update 2: I have noticed a couple of minor logic errors as well, but they appear to be easy enough to correct.

--MidLifeXis

Replies are listed 'Best First'.
Re^2: Another word puzzle with too many permutations
by MidLifeXis (Monsignor) on Oct 15, 2013 at 18:13 UTC
      Well, I ran your code using my 4 car example and it gave the right solution. I had mixed results with the dogs but it could be an issue on my side. I am running some more tests but I think this may be the path to what I am looking for. Thank you for taking the time to put a working script together.

        The issue was mentioned on a different node. You specify an alphabet, but your data contains characters not contained in that alphabet. You can either filter the characters that you are not checking ('-', '.'), add them to the alphabet, or remove them from the data in your list of items.

        --MidLifeXis

Re^2: Another word puzzle with too many permutations
by sarchasm (Acolyte) on Oct 15, 2013 at 17:25 UTC
    I agree that I need to figure out some way to use the pool of letters in the process to detect when the list is going down a path that doesn't fit the solution. I will think about your pseudocode and see if I can come up with anything. Thank you.