Coder Social home page Coder Social logo

scrabble-solver's Introduction

scrabble-solver

This service looks up English words comprised of user-supplied letters.

It is a Spring Boot project built using Maven. As such, the project can be imported via the pom file and launched via the main() method in ScrabbleSolverApplication.java during development.

The next step would be to put in the Aho–Corasick algorithm to reduce the cost of computing words. Maybe some other project or time...

Starting the service

To start the application, simply execute the bundled jar from its local directory using command:

java -jar scrabble-solver.jar

Implementation details

Upon application bootstrap, the WordLookupService loads the list of valid words into memory from a flat file. This is an O(n) operation where n is a word/line of text in the file.

In findWordsFromLetters(), the WordLookupService uses the LetterUtility to sort and trim the user input for comparison against the given word during iteration. It then iterates over the list using the Java streaming api using a filter for "containment check" and PointValue lookup for ordering the resultant list.

The "containment check" is the containsIgnoringOrder() method of LetterUtility. It sorts the letters of the word and those of the input (each an O(nlog(n)) operation where n is the character) and then iterates the letters keeping an index into the letters of the word, moving it forward when the letters match. Since the letters are sorted, a number of assumptions are made about the word and the input letters:

  • If the word has more characters than the input letters, return false.
  • If the character of letters is greater than the character of words, then the word contains a letter that does not exist in the word. Return false.
  • If the index of the word reaches the end of the word, then the word is contained in the letters. Return true.
  • If the letters are iterated successfully, the method returns with one last check that the word was iterated entirely (not true if the word contains characters of higher value than the input letters)

Sorting the inputs: O(nlog(n)). Iterating the letters: O(n)

Finally, WordLookupService utilizes SpringBoot's caching to cache results of findWordsFromLetters() so as to reduce the need to perform the operation when it has already been performed.

Next steps

Increase code coverage Add Spring-ified integration tests (test context-based) Add System tests (Rest Assured/maven-failsafe-plugin) Add Perf tests (Gatling) Pre-warm the cache for WordLookupService? Profile the memory usage of the service under load Tune the performance

Not covered in spec

The word list contains words with apostrophes. Scrabble does not allow words with special characters, so we filter them out upon loading of the word list

scrabble-solver's People

Contributors

kthblmfld avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.