aboutsummaryrefslogtreecommitdiff
path: root/challenge-267/eric-cheung/python/ch-2.py
diff options
context:
space:
mode:
authorPacky Anderson <PackyAnderson@gmail.com>2024-05-06 23:41:04 -0400
committerGitHub <noreply@github.com>2024-05-06 23:41:04 -0400
commit8da3f7983b54d8c8eb96326f4d7f3d52f1a78d9b (patch)
tree4cc9a6443382d2a32208246c481cd566b6ea0142 /challenge-267/eric-cheung/python/ch-2.py
parente4a2c66b30346606d347ecc4a08b83b733797d2a (diff)
parentc1756b0e7aed0ad70fa63feb2565c69215c9d426 (diff)
downloadperlweeklychallenge-club-8da3f7983b54d8c8eb96326f4d7f3d52f1a78d9b.tar.gz
perlweeklychallenge-club-8da3f7983b54d8c8eb96326f4d7f3d52f1a78d9b.tar.bz2
perlweeklychallenge-club-8da3f7983b54d8c8eb96326f4d7f3d52f1a78d9b.zip
Merge branch 'manwar:master' into challenge-268
Diffstat (limited to 'challenge-267/eric-cheung/python/ch-2.py')
-rwxr-xr-xchallenge-267/eric-cheung/python/ch-2.py29
1 files changed, 29 insertions, 0 deletions
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])