diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 9ae4f93..2a4fb38 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -3,14 +3,31 @@ PLEASE FILL IN THE FOLLOWING! ## Full Name -John Johnson +Zain-Ul-Ebad Raza +otherwise known as **big z** ## UWindsor Email -john.johnson@uwindsor.ca +razaz@uwindsor.ca ## Application Form -- [ ] I certify I have submitted the [application form](https://forms.office.com/r/R4A1JyB3Xf) +- [x] I certify I have submitted the [application form](https://forms.office.com/r/R4A1JyB3Xf) ## Briefly explain how your solution works and how to run it -My solution... +### Explanation +My solution is a depth first search solution that checks all decision paths from a certain character. There are a couple of false exit cases such as index being out of range and the current character being checked does not match `word[i]`. There's also some temp variable fuckery just so that it doesn't visit an already checked index. + +### How to Build +It works in terminal, enter your command like this (once u cd in): + +`python3 solution.py ` + +you're supposed to enter in the parameters like you would if you were coding the function yourself so here are a couple of examples. + +`python3 solution.py [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]] "ABCCED"` + +`python3 solution.py [["A"]] "A"` + +`python3 solution.py [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]] "ABCCEDO"` + +alternatively you could be a lazy fuck and just copy and paste the function into LeetCode like a fkn demon but I just recommend you make a script or something idgaf ima go spend my time learning 4th grade french. \ No newline at end of file diff --git a/solution.py b/solution.py new file mode 100644 index 0000000..698e31b --- /dev/null +++ b/solution.py @@ -0,0 +1,49 @@ +import argparse + +parser = argparse.ArgumentParser( + description="Given a two-dimensional grid of letters and a word as inputs, determine whether the word can be constructed in the grid." +) + +parser.add_argument("board", help="2D List to be served as board/grid to search", type=list[list[str]]) +parser.add_argument("word", help="word to search for on board/grid", type=str) + +args = parser.parse_args() + +def exist(board: list[list[str]], word: str) -> bool: + + def dfs(i, x, y): + if i >= len(word): + return True + if not(0 <= x < len(board)) or not(0 <= y < len(board[0])): + return False + if board[x][y] != word[i]: + return False + + temp = board[x][y] + board[x][y] = "jeremie bornais is a rat bastard and we should impeach his ass and instead promote big z, only then would there be meaningful change #FuckJeremie #ILoveLarry" + res = dfs(i+1, x+1, y) or dfs(i+1, x-1, y) or dfs(i+1, x, y+1) or dfs(i+1, x, y-1) + board[x][y] = temp + return res + + for i in range(len(board)): + for j in range(len(board[0])): + if dfs(0, i, j): + return True + return False + + +# Dumb shit converting argument into actual 2D List +board = [] +l = 1 +while l < len(args.board) - 1: + if args.board[l] == '[': + temp = [] + r = l + 1 + while args.board[r] != ']': + if args.board[r] != ',': + temp.append(args.board[r]) + r += 1 + board.append(temp) + l += 1 + +print(exist(board, args.word)) \ No newline at end of file