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

Team A Submission - Zain Raza #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <board> <word>`

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.
49 changes: 49 additions & 0 deletions solution.py
Original file line number Diff line number Diff line change
@@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👁

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))