Graeme Cole wrote: ↑Wed Aug 07, 2024 12:01 pmYep, generating all the permutations of a 9 letter word is the red flag here.Fiona T wrote: ↑Wed Aug 07, 2024 7:21 amyeah I considered that but figured you could think "yes I know"Graeme Cole wrote: ↑Wed Aug 07, 2024 12:25 am You might want to exclude the scramble itself from the possible solutions. It's valid for the scramble to be a valid word if there's only one anagram of it, but if you feed the conundrum checker "RAUNCHIER HURRICANE", for example, it complains that there are two solutions.But yeah easy enough to exclude it. (Edit - done)
It's probably a bit quicker than that but still slower than I'd like.Graeme Cole wrote: ↑Wed Aug 07, 2024 12:25 am
That sounds optimisable. What does it do to check a conundrum?
It's basically doing the same as I've done with RoboRiley - I've got a trie structure with the dictionary in, I then get all the permutations (362880 for 9 letters without repeats) stick those in a trie and compare tries. Tries are pretty efficient - I think it's the permutations thing that needs optimising - will have a google...
If you've already got a list of all the valid words, you could arrange the letters within each valid word in alphabetical order, then build a sorted list of the resulting strings (or put them in a trie, if you prefer). For example, ACDEINOTU would appear in the list three times, consecutively. Now you only have to check one permutation of the scramble, look it up in your pre-computed sorted list, and count how many times it appears.
There are ways of improving on this (e.g. include the count in the list like ["ACDEINOTU", 3] rather than repeating the strings), but the main thing is you don't have to generate every permutation of the scramble.
Fiona T wrote: ↑Thu Aug 08, 2024 9:46 amYeah but I'm not checking 9! words - by putting the permutations into a trie, if the scramble is ABCXEANRI once CX is ruled out, then all the words that start with CX are ruled out etc... Anyway - probably sidetracking this thread from its original purpose - will have a play and do some comparisons.Graeme Cole wrote: ↑Wed Aug 07, 2024 7:17 pm What if you just iterate over the whole dictionary, checking every valid word to see if it's an anagram of the scramble? (Or, for the general case, that the word is available from the scramble?) I think even that would still be faster than checking every permutation of the scramble to see if it's a valid word. Checking if one string is an anagram of another is basically the same algorithmic complexity as finding a string in a trie, but there are four times as many permutations of 9 letters as there are 1-9 letter words in the dictionary.
Anyway - for the conundrum checker I did as Graeme suggested and created (from my dictionary trie) an alphagram dictionary with a count, and that worked beautifully.
Was reasonably happy with the RoboRiley word finder on 9 letter words, but as soon as you went to 10 there was a delay and 12 letters became very noticeable.
I was putting the permutations of the selection into a trie and comparing to the dictionary trie - the compare bit was super quick.
It occurred to me I didn't need to put the permutations into a trie - just adapt that code to directly search the dictionary trie and stop then when you get to a non-existent prefix so saving 1000s of iterations (e.g. when it hits CX it doesn't need to create any further iterations of that prefix). It works instantly now, and no noticeable lag with longer selections, so lots of future possibilities...

