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

My solution (updated) #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

CalderJohnson
Copy link
Member

@CalderJohnson CalderJohnson commented Dec 4, 2022

CS Games 2023 Team A Application

PLEASE FILL IN THE FOLLOWING!

Full Name

Calder Johnson

UWindsor Email

[email protected]

Application Form

Briefly explain how your solution works and how to run it

This is an amendment to my previous submission, a bug was fixed PLEASE MAKE SURE TO TEST THE CURRENT VERSION OF THE SOLUTION :)

My solution is written in python and should be ran using an up-to-date python 3 interpreter. It accepts input with the format specified by the problem, and it is case sensitive (though making it case insensitive would be the small matter of updating the driver code).

My solution makes use of a wrapper function and an inner recursive function which does most of the work to validate the words. First, I initialize a result boolean variable which I default to false. Then, I use a pair of for loops to locate every instance of the first letter in the word we're trying to find in the grid. I call my inner function on each instance of that letter.

My inner function accepts the grid, a word, and the row and column of the letter in question. Each time, if its cell is on the correct next letter, it will call itself on every adjacent cell, sending the grid with the letter just checked removed to prevent repeats, and sending the word with the first letter removed so that the next letter can be checked. I always validate the case that the function is called on invalid indexes (doing nothing in that case). When the function receives an empty word, its base case is reached as every letter must have been found and the word is present, returning true. After calling on each adjacent cell, I replace the letter so as to not modify the grid for other branches of the search.

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

Successfully merging this pull request may close these issues.

1 participant