Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

added kashaf_jabeen file #24

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
47 changes: 47 additions & 0 deletions kashaf_jabeen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
def minesweeper(A):
#code that coverts the test matrix into desired output
rows=len(A)
cols=len(A[0])
A=[list(A[i]) for i in range(rows)]

for i in range(rows):
for j in range(cols):
if A[i][j] != "X":
counter=0
for k in range(i-1, i+2):
for l in range(j-1, j+2):
if (-1<k<rows and -1<l<cols) and A[k][l]=="X":
counter += 1

A[i][j]=str(counter)

A=[''.join(A[i]) for i in range(rows)]

return A



if __name__=="__main__":

test = ["XOOXXXOO",
"OOOOXOXX",
"XXOXXOOO",
"OXOOOXXX",
"OOXXXXOX",
"XOXXXOXO",
"OOOXOXOX",
"XOXXOXOX"]

# """Desired Output is as under

# ["X11XXX32",
# "3335X5XX",
# "XX3XX554",
# "3X556XXX",
# "24XXXX6X",
# "X3XXX5X3",
# "245X6X5X",
# "X2XX4X4X"]
# """

print(minesweeper(test))