Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Even faster solution: ~1 Minute #3

Open
fabmax opened this issue Aug 6, 2022 · 0 comments
Open

Even faster solution: ~1 Minute #3

fabmax opened this issue Aug 6, 2022 · 0 comments

Comments

@fabmax
Copy link

fabmax commented Aug 6, 2022

Sorry for mis-using the issues section here to share my results, but I couldn't resist 😄

My solution finds all 538 sets in around 50 seconds (with multi-threading on an 8-core CPU).

I'm not using fancy math (I know that's nothing to be proud of) but a few other tricks, which appear to speed things up a little:

  • Valid five-word sets must use 25 out of 26 characters. Therefore, I select words containing two rare letters
    (x and / or q, there are only 315 such words) and use only them as 'seed words'. Then I only have to find four
    more words per seed word. Because every valid set must contain either an x and / or a q I can't miss a set.

  • Initially, I build 26 sets (one for each letter) containing all words that include the particular letter. This
    helps in efficiently removing invalid word candidates later on.

  • The search function works recursively and removes invalid words from the list of candidates for deeper recursion
    levels (using the words-by-letter sets mentioned above). This way the search can terminate early once there are no more word candidates left.

The code is pretty simple (~150 lines including comments), however I used kotlin as programming language instead of python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant