aboutsummaryrefslogtreecommitdiff
path: root/challenge-248/eric-cheung/python
diff options
context:
space:
mode:
authorJoelle Maslak <jmaslak@antelope.net>2023-12-20 19:53:33 -0700
committerGitHub <noreply@github.com>2023-12-20 19:53:33 -0700
commitac10d33ad4be2763bba001150bef6e838d017546 (patch)
treea465bedb1a1bbbe6380c3c169404bf4565b893c3 /challenge-248/eric-cheung/python
parent80750c8e164c159fe869b652be98a1eef64373dd (diff)
parent33f4358de5040ddc31b53689b6a781efbc2847c1 (diff)
downloadperlweeklychallenge-club-ac10d33ad4be2763bba001150bef6e838d017546.tar.gz
perlweeklychallenge-club-ac10d33ad4be2763bba001150bef6e838d017546.tar.bz2
perlweeklychallenge-club-ac10d33ad4be2763bba001150bef6e838d017546.zip
Merge branch 'manwar:master' into master
Diffstat (limited to 'challenge-248/eric-cheung/python')
-rwxr-xr-xchallenge-248/eric-cheung/python/ch-1.py21
-rwxr-xr-xchallenge-248/eric-cheung/python/ch-2.py13
2 files changed, 34 insertions, 0 deletions
diff --git a/challenge-248/eric-cheung/python/ch-1.py b/challenge-248/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..6a7dab3628
--- /dev/null
+++ b/challenge-248/eric-cheung/python/ch-1.py
@@ -0,0 +1,21 @@
+
+## Example 1
+## strInput = "loveleetcode"
+## strChar = "e"
+
+## Example 2
+strInput = "aaab"
+strChar = "b"
+
+arrCharIndx = [nIndx for nIndx in range(len(strInput)) if strInput[nIndx] == strChar]
+arrOutput = []
+
+for nIndx in range(len(strInput)):
+ if strInput[nIndx] == strChar:
+ arrOutput.append(0)
+ elif nIndx < arrCharIndx[0]:
+ arrOutput.append(arrCharIndx[0] - nIndx)
+ else:
+ arrOutput.append(min([abs(nLoop - nIndx) for nLoop in arrCharIndx]))
+
+print (arrOutput)
diff --git a/challenge-248/eric-cheung/python/ch-2.py b/challenge-248/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..61e8e84fd1
--- /dev/null
+++ b/challenge-248/eric-cheung/python/ch-2.py
@@ -0,0 +1,13 @@
+
+## arrMatrixInput = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] ## Example 1
+arrMatrixInput = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] ## Example 2
+
+arrMatrixOutput = []
+
+for nRow in range(len(arrMatrixInput) - 1):
+ arrRow = []
+ for nCol in range(len(arrMatrixInput[nRow]) - 1):
+ arrRow.append(arrMatrixInput[nRow][nCol] + arrMatrixInput[nRow][nCol + 1] + arrMatrixInput[nRow + 1][nCol] + arrMatrixInput[nRow + 1][nCol + 1])
+ arrMatrixOutput.append(arrRow)
+
+print (arrMatrixOutput)