Speed up a slow loop
alex at tweedly.net
Mon Mar 7 13:30:28 EST 2022
On 06/03/2022 22:56, J. Landman Gay via use-livecode wrote:
> The board walk took 179 ms for all 108 words because I ditched my old,
> juvenile, inefficient code and swiped yours. :) As Bill requested,
> I've marked all the stuff I used with credits for the people who
> suggested or provided code, so you're in there. The two most impactful
> changes were your board walk and Quentin's filtered dictionary idea,
> but there are also other improvements.
Oh, well, if you've got the fast boardwalk code in there anyway, that
opens up another possibility (with one caveat).
The boardwalk will find all valid words on the board. So that list of
words can be used as the "dictionary" for the user's guesses - and now
you have a "dictionary" of only a few hundred words, rather than than
the many thousands of either the original or the filtered dictionaries.
And it's worth saying that the fast boardwalk only explores those
potential words that are on the board, so there's no need to filter the
dictionary for it.
The caveat - a user guess which isn't in the word list found by the
boardwalk can be either "not a word" or "a word, but not present on the
board", and you don't know which. If your UI needs to distinguish
between those cases, you'd need to do another step of checking these
(hopefully very few) failure cases against the full dictionary.
More information about the use-livecode