Skip to content

Commit

Permalink
Added Python, Structured Repo
Browse files Browse the repository at this point in the history
  • Loading branch information
rehanguha committed Jun 30, 2020
1 parent 4adbe77 commit 96e5629
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 136 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vscode
gridsearching_dev
2 changes: 1 addition & 1 deletion GridSearching.cpp → C++/GridSearching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ int grid_search(int arr[MAX][MAX],int NUM,int n=MAX)

int main()
{
int arr[MAX][MAX]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};
int arr[MAX][MAX]={{71,2,3,84},{5,66,7,8},{9,180,11,182},{413,3414,515,126}};
int num;
cout<<"Enter no.:";
cin>>num;
Expand Down
File renamed without changes.
File renamed without changes.
78 changes: 78 additions & 0 deletions Python/GridSearching.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
def _range(n):
t = 0
if n % 3 == 1:
t = ((n+2)/3)
elif n%3 == 2:
t = ((n+1)/3)
else:
t=((n)/3)
return t*t

def check(A, i, j, NUM, dim):
if ((i>=0 and i<dim) and (j>=0 and j<dim) and A[i][j]==NUM):
return 1
return 0


def GridSearch(A, NUM, dim):
flag = False
f_i = f_j = None
t = int(_range(dim))
for i in range(1, t+1, 3):
for j in range(1, t+1, 3):
if check(A, i-1, j-1, NUM, dim):
flag = True
f_i = i-1
f_j = j-1
break
if check(A, i-1, j, NUM, dim):
flag = True
f_i = i-1
f_j = j
break
if check(A, i, j-1, NUM, dim):
flag = True
f_i = i
f_j = j-1
break
if check(A, i-1, j+1, NUM, dim):
flag = True
f_i = i-1
f_j = j+1
break
if check(A, i, j, NUM, dim):
flag = True
f_i = i
f_j = j
break
if check(A, i, j+1, NUM, dim):
flag = True
f_i = i
f_j = j+1
break
if check(A, i+1, j, NUM, dim):
flag = True
f_i = i+1
f_j = j
break
if check(A, i+1, j+1, NUM, dim):
flag = True
f_i = i+1
f_j = j+1
break
if flag:
break

return flag, f_i, f_j

if __name__ == "__main__":
A = [[12,2,31,44],[5,36,7,82],[9,310,121,132],[313,145,515,616]]

SearchNumber = 515

found, i, j = GridSearch(A,SearchNumber, len(A))

if found:
print(i,",",j)
else:
print("Not Found")
135 changes: 0 additions & 135 deletions q.cpp

This file was deleted.

0 comments on commit 96e5629

Please sign in to comment.