in reply to Re^8: Words in Words
in thread Words in Words
Then, I go through the words one by one. For each word, I try all the positions and all possible lengths of its subwords (and I skip the maximal length at position 0, because that would breake the rule #2). For each subword, I do nothing if it has already been printed out (each word should be reported just once). I do nothing if rules #3 or #4 apply. Otherwise, I check whether the subword is itself on the list of words. If it is, I report it and book it as such. And that's it.
The basic idea was this: Comparing each word to all other words would take ages. There would be many comparisons of words that are totally incompatible. How can I reduce the number of comparisons? I do not need all the words, I only need those that are possible for the given word.
As I read the code know, I think it might be optimized a bit further. Instead of caching the reported subwords, you can cache the tested ones (i.e. move the undef three lines up, before the "if"). %reported should be renamed to %checked then.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^10: Words in Words
by sarchasm (Acolyte) on Oct 03, 2011 at 00:06 UTC | |
by Anonymous Monk on Oct 03, 2011 at 00:16 UTC | |
by sarchasm (Acolyte) on Oct 03, 2011 at 04:10 UTC |