Skip to content

Unscrambler is a highly optimized dotnet package. It implements an algorithm that is able to find all words that can be made from a list of letters.

License

Mnjongen/Unscramble

Repository files navigation

Unscramble

Unscramble is a .NET package that can help you find all possible words from a list of letters. It is useful for solving word puzzles, crossword clues, or anagrams. Unscramble is fast, easy to use, and highly optimized.

publish NuGet Version NuGet Downloads

Installation

You can install Unscramble from NuGet, the package manager for .NET. To install Unscramble, run the following command in your terminal:

dotnet add package Unscramble

Usage

Loading words

Before you can use Unscramble to find words, you need to load the words into the an instance of IUnscramble. You can use any list of words that you want, as long as they are in a text file where each word is on a new line. You can find some examples of word lists online, such as:

To load the words from a file, you can use the BasicWordLoader class that comes with the package. It takes an IUnscramble object and a file path as parameters, and returns a boolean value indicating whether the loading was successful or not.

IUnscramble Unscramble = new BasicUnscramble();
IWordLoader loader = new BasicWordLoader("words.txt");

// Load words from a file
bool success = await loader.LoadFromFileAsync(Unscramble);

// If success is true, the words are loaded successfully

Implementing your own word loader

If you are already loading your words from a database or another source, can add the words to a IUnscramble like this:

IUnscramble Unscramble = new BasicUnscramble();
foreach (string word in words)
{
    Unscramble.AddWord(word);
}

You can also create your own implementation of the IWordLoader interface if you want to load words from a different source.

Finding words

Once you have loaded the words into the package, you can use the Unscramble method to find all the words that can be made from a list of letters. The method takes a string of letters as a parameter, and returns a HashSet<string> object that contains all the words found.

HashSet<string> words = Unscramble.Unscramble("letters");

You can then iterate over the HashSet<string> object to access the words, or use any other methods that are available for the HashSet<T> class.

Example

Here is a full example of how to use Unscramble to find words from a list of letters and print them to the console:

IUnscramble Unscramble = new BasicUnscramble();
IWordLoader loader = new BasicWordLoader("words.txt");

// Load words from a file
bool success = await loader.LoadFromFileAsync(Unscramble);

if (success)
{
    // Find words from a list of letters
    HashSet<string> words = Unscramble.Unscramble("letters");

    // Print the words to the console
    foreach (string word in words)
    {
        Console.WriteLine(word);
    }
}
else
{
    Console.WriteLine("Failed to load words from file.");
}

About

Unscrambler is a highly optimized dotnet package. It implements an algorithm that is able to find all words that can be made from a list of letters.

Resources

License

Stars

Watchers

Forks

Languages