aboutsummaryrefslogtreecommitdiff
path: root/challenge-267/adam-russell/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-267/adam-russell/python/ch-2.py')
-rw-r--r--challenge-267/adam-russell/python/ch-2.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/challenge-267/adam-russell/python/ch-2.py b/challenge-267/adam-russell/python/ch-2.py
new file mode 100644
index 0000000000..a2a476eb12
--- /dev/null
+++ b/challenge-267/adam-russell/python/ch-2.py
@@ -0,0 +1,18 @@
+WIDTH = 100
+
+def line_counts(s, widths):
+ width = 0
+ line_count = 1
+ for c in s:
+ width = width + widths[ord(c) - ord("a")]
+ if(width > WIDTH):
+ width = widths[ord(c) - ord("a")]
+ line_count = line_count + 1
+ return line_count, width
+
+s = "abcdefghijklmnopqrstuvwxyz"
+widths = (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)
+print(line_counts(s, widths))
+s = "bbbcccdddaaa"
+widths = (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)
+print(line_counts(s, widths))