From 0e5da5a08105ac626778f40f9e65001106e13696 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Thu, 11 Apr 2024 03:42:33 +0530 Subject: [PATCH 1/5] hello World #1 --- practice/hello-world/hello_world.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice/hello-world/hello_world.py b/practice/hello-world/hello_world.py index adaa6c2..d695ea1 100644 --- a/practice/hello-world/hello_world.py +++ b/practice/hello-world/hello_world.py @@ -1,2 +1,2 @@ def hello(): - return 'Goodbye, Mars!' + return 'Hello, World!' From 95931877024fdd8519820db0b0e83f9b8c16a9e0 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Thu, 11 Apr 2024 23:48:39 +0530 Subject: [PATCH 2/5] Revert "hello World #1" This reverts commit 0e5da5a08105ac626778f40f9e65001106e13696. --- practice/hello-world/hello_world.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice/hello-world/hello_world.py b/practice/hello-world/hello_world.py index d695ea1..adaa6c2 100644 --- a/practice/hello-world/hello_world.py +++ b/practice/hello-world/hello_world.py @@ -1,2 +1,2 @@ def hello(): - return 'Hello, World!' + return 'Goodbye, Mars!' From 26c78dcaaf5fc328732d770aa8d7eff5172b4629 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Tue, 16 Apr 2024 00:35:58 +0530 Subject: [PATCH 3/5] minesweeper --- .../__pycache__/minesweeper.cpython-39.pyc | Bin 0 -> 1336 bytes ...nesweeper_test.cpython-39-pytest-6.2.4.pyc | Bin 0 -> 3887 bytes practice/minesweeper/minesweeper.py | 29 ++++++++++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 practice/minesweeper/__pycache__/minesweeper.cpython-39.pyc create mode 100644 practice/minesweeper/__pycache__/minesweeper_test.cpython-39-pytest-6.2.4.pyc diff --git a/practice/minesweeper/__pycache__/minesweeper.cpython-39.pyc b/practice/minesweeper/__pycache__/minesweeper.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000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 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 practice/minesweeper/__pycache__/minesweeper.cpython-39.pyc delete mode 100644 practice/minesweeper/__pycache__/minesweeper_test.cpython-39-pytest-6.2.4.pyc diff --git a/practice/minesweeper/__pycache__/minesweeper.cpython-39.pyc b/practice/minesweeper/__pycache__/minesweeper.cpython-39.pyc deleted file mode 100644 index feac08ac870d84d9b84ba79a04c3f7fe2d53bd73..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1336 zcmZuwzi-r75T1FqH_qNB;+F#9xRZ6FU{kD+D2UK%g+yqhlY*iX+Hf*{FN?E|z5D!@ zgvh2KkyxlgN6D4+{2|n@y(-N$*U`X?gF}+Lx0>1aX6DWN=9_UiH`fGOy}e&H|8W5R z=ELbF=y0DTZ;_H9@c6SA|zA2W@zJ+P!7mnl4pv!KY%qb@ESK!q7(=I6jxv$ z_fg+AC>^p;)OX9W5z^hqS7@9mMX;9MB1H=*@eRBN%F&QB2flF&^7E}y)ccLMrDNPF z*;ZhqDBUR*&LR}<>zQ$}wn z$p5?iskV{-n(^urvr_N7aERj;3CI?)1BGB_s5^73XWGMU^hoY-dwwHTz{d3w4KSGo zrXZ=5eH@B)AQFV+6yk{DV6~0bNmTk#Skbv{9i8ovWp+DG)n=>``4PT!SMK%K*MbL` zRQ*AoMSZoabQI^?{gDnM6Gy7g;rWhIBc)I8JEIqNwmVR%+8ya01N@iY-1|99)69fM zb-GCwg-PD)oJ5_ei^t6+$yowYRM)i<3m$~|QWQeMbF6A=)>Z9^U};tJytW<9cQwCj zF{*6GiYHmml46(UFJ$l5qh~63nuS^haUR6!^Dv2JuoIhSK{U}?rG|{7iRozmEY5&r z^7*05B>4iV0mGaxQNjSHa0T9pu}g$wb@dpUsGwQ=lgM_XEXjWWv(0W2=O)UwM?J=P zjPJ((P<9e#ajESbeWg`Bal{byMN$@n|3KxM*GSGm{Xnzw7uHZM!L{yI7N?qfaGtw) zvfW@ibJuQICrlDj=?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a3e>d_Tj(>a{jmpoUz>J(Pp}@?SpTzY09y!+01;}55gpfMAp35 zJ9I~_RkwGD=Gn;o4ZLWBvjZL^;8-J7Rv+pbFj-pD Date: Mon, 22 Apr 2024 19:55:56 +0530 Subject: [PATCH 5/5] improved the code --- practice/minesweeper/minesweeper.py | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/practice/minesweeper/minesweeper.py b/practice/minesweeper/minesweeper.py index 19b608c..13113e9 100644 --- a/practice/minesweeper/minesweeper.py +++ b/practice/minesweeper/minesweeper.py @@ -1,13 +1,41 @@ def annotate(minefield): + """ + Annotate a minefield with the number of mines each square is adjacent to. + + The minefield is represented as a list of strings. Each string represents a row of the minefield, + with '*' representing a mine and ' ' representing an empty square. + + The function returns a new minefield where each empty square is replaced with the number of mines + that square is adjacent to. If a square is adjacent to no mines, it is replaced with a space. + + Args: + minefield (list): A list of strings representing the minefield. + + Returns: + list: A list of strings representing the annotated minefield. + + Raises: + ValueError: If the minefield is not a rectangle or contains invalid characters. + + Examples: + >>> annotate([" * ", " ", " * "]) + ['1*1', '232', '1*1'] + """ + # If the minefield is empty, return an empty list if not minefield: return [] + # Check if the minefield is a rectangle and contains only valid characters if not all(len(row) == len(minefield[0]) for row in minefield) or any(c not in ' *' for row in minefield for c in row): raise ValueError("The board is invalid with current input.") + # Get the number of rows and columns in the minefield rows, cols = len(minefield), len(minefield[0]) + + # Initialize a 2D list to store the counts of adjacent mines counts = [[0]*cols for _ in range(rows)] + # For each square in the minefield, if it is a mine, increment the count of all adjacent squares for i in range(rows): for j in range(cols): if minefield[i][j] == '*': @@ -16,6 +44,7 @@ def annotate(minefield): if 0 <= i+di < rows and 0 <= j+dj < cols: counts[i+di][j+dj] += 1 + # Replace each count with a string, leaving mines as '*' and replacing 0 with ' ' for i in range(rows): for j in range(cols): if minefield[i][j] == '*': @@ -25,4 +54,5 @@ def annotate(minefield): else: counts[i][j] = str(counts[i][j]) + # Join each row into a string and return the annotated minefield return [''.join(row) for row in counts] \ No newline at end of file