CS Games 2023 Team A Application in C++ and/or Python #11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
CS Games 2023 Team A Application
PLEASE FILL IN THE FOLLOWING!
Full Name
Cole Fuerth
UWindsor Email
[email protected]
Application Form
Briefly explain how your solution works and how to run it
Brief
I first developed my solution in Python, then remade it in C++ for speed. I would prefer the C++ solution to be considered, since it is considerably faster, but it should still be noted that the Python solution came first, and runs almost as fast. The Python is also (understandably) much easier to read and understand, since the solutions are very much the same algorithmically.
How it works
My solution first tries to find exceptional cases that clearly will not fit first, then picks the better order of characters of the word (reversing the word will not change whether it fits the puzzle, and the order with the least starting points runs exponentially faster). Once it is known all the characters in the string appear on the board frequent enough to potentially fit, and that we have the optimal order of characters, a depth first approach is employed. Using sets to keep track of points, the board, and history, we can keep track of everything using set operations.
dfs
exhaustively tries all possible paths for the string, until eventually either fitting or exhausting all possibilities.Running the code
On leetcode (how I assume you are testing), you can copy and paste either of the solutions that are found under the leetcode folder directly onto the site. The C++ solution is in the top 1.5% of submissions; the Python solution is in the top 10% for runtime.
Locally, I am testing using
make
with the provided Makefile, orpython3 solution.py
. The test case is hard coded intomain
on each of the source files in the root directory.