aboutsummaryrefslogtreecommitdiff
path: root/challenge-267/eric-cheung/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-267/eric-cheung/python')
-rwxr-xr-xchallenge-267/eric-cheung/python/ch-1.py8
-rwxr-xr-xchallenge-267/eric-cheung/python/ch-2.py29
2 files changed, 37 insertions, 0 deletions
diff --git a/challenge-267/eric-cheung/python/ch-1.py b/challenge-267/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..c3f56490de
--- /dev/null
+++ b/challenge-267/eric-cheung/python/ch-1.py
@@ -0,0 +1,8 @@
+
+## arrInt = [-1, -2, -3, -4, 3, 2, 1] ## Example 1
+## arrInt = [1, 2, 0, -2, -1] ## Example 2
+arrInt = [-1, -1, 1, -1, 2] ## Example 3
+
+arrNegCount = [nLoop for nLoop in arrInt if nLoop < 0]
+
+print (0 if 0 in arrInt else 1 if len(arrNegCount) % 2 == 0 else -1)
diff --git a/challenge-267/eric-cheung/python/ch-2.py b/challenge-267/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..813851dabb
--- /dev/null
+++ b/challenge-267/eric-cheung/python/ch-2.py
@@ -0,0 +1,29 @@
+
+## Example 1
+## strInput = "abcdefghijklmnopqrstuvwxyz"
+## arrCharWidth = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
+
+## Example 2
+strInput = "bbbcccdddaaa"
+arrCharWidth = [4, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
+
+
+nMaxUnitPerLine = 100
+
+arrLineOutput = []
+nLineUnitCount = 0
+strLineAppend = ""
+
+for charLoop in strInput:
+ nIndx = ord(charLoop) - ord("a")
+ if nLineUnitCount + arrCharWidth[nIndx] > nMaxUnitPerLine:
+ arrLineOutput.append(strLineAppend)
+ nLineUnitCount = 0
+ strLineAppend = ""
+
+ strLineAppend = strLineAppend + charLoop
+ nLineUnitCount = nLineUnitCount + arrCharWidth[nIndx]
+
+arrLineOutput.append(strLineAppend)
+
+print ([len(arrLineOutput), nLineUnitCount])