Further to the discussion here: Anagram solving by Regex or SQL I have been presented with a new challenge....
A word game presents you with 9 letters at random. When I say random, the balance between vowels and consonants is selected by the player so as to offer the best chance of making the longest word. The vowels/consonants chosen are generated at random and might be duplicated. Each letters may only be used once, and the player finding the longest word is the winner! Those of you familiar with 'Countdown' or 'Des Chiffres Et Des Lettres' will already understand the game.
I am employing an SQL database that is already populated with c350k words and the 'Signature' of each word that was previously generated for solving anagrams, for example: 'abandoned' has a signature of 'a2b1d2e1n2o1'.
Making the first pass searching for 9 letter matches is really easy as you generate a 'Signature' from the 9 letters and look for matches. Thereafter it starts to get complicated. If you don't find any 9 letter words you have to start excluding letters from the signature in a manner that covers all possible permutations. Let's say I am not interested in 4 letter words so I need to scan all possibilities from 9 down to 5 letters.
What is the most logical method?
For 8 letters I carry out 8 SQL SELECT passes excluding a single character from the signature in sequence 1-9.
For 7 letter words I need to exclude 2 letters at each SELECT pass..... So 1+2, 1+3, 1+4.... until 1+9. The 2+3, 2+4 etc....
As you can see by the time you get to 5 letters there has been an awful lot of SQL activity and I am starting to think there must be a much better way of doing this!
Any suggestions?
A word game presents you with 9 letters at random. When I say random, the balance between vowels and consonants is selected by the player so as to offer the best chance of making the longest word. The vowels/consonants chosen are generated at random and might be duplicated. Each letters may only be used once, and the player finding the longest word is the winner! Those of you familiar with 'Countdown' or 'Des Chiffres Et Des Lettres' will already understand the game.
I am employing an SQL database that is already populated with c350k words and the 'Signature' of each word that was previously generated for solving anagrams, for example: 'abandoned' has a signature of 'a2b1d2e1n2o1'.
Making the first pass searching for 9 letter matches is really easy as you generate a 'Signature' from the 9 letters and look for matches. Thereafter it starts to get complicated. If you don't find any 9 letter words you have to start excluding letters from the signature in a manner that covers all possible permutations. Let's say I am not interested in 4 letter words so I need to scan all possibilities from 9 down to 5 letters.
What is the most logical method?
For 8 letters I carry out 8 SQL SELECT passes excluding a single character from the signature in sequence 1-9.
For 7 letter words I need to exclude 2 letters at each SELECT pass..... So 1+2, 1+3, 1+4.... until 1+9. The 2+3, 2+4 etc....
As you can see by the time you get to 5 letters there has been an awful lot of SQL activity and I am starting to think there must be a much better way of doing this!
Any suggestions?