Skip to content

Even faster solution: ~1 Minute #3

@fabmax

Description

@fabmax

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions