aboutsummaryrefslogtreecommitdiff
path: root/challenge-325/packy-anderson/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-325/packy-anderson/python/ch-1.py')
-rwxr-xr-xchallenge-325/packy-anderson/python/ch-1.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/challenge-325/packy-anderson/python/ch-1.py b/challenge-325/packy-anderson/python/ch-1.py
new file mode 100755
index 0000000000..788c6bb951
--- /dev/null
+++ b/challenge-325/packy-anderson/python/ch-1.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+
+def consecutiveOne(binary):
+ max_c = 0
+ consecutive = 0
+ for bit in binary:
+ if bit == 1:
+ consecutive += 1
+ if consecutive > max_c: max_c = consecutive
+ else:
+ consecutive = 0
+ return max_c
+
+def int_join(joiner, arr):
+ return joiner.join(map(lambda i: str(i), arr))
+
+def solution(binary):
+ print(f'Input: @binary = ({int_join(", ", binary)})')
+ print(f'Output: {consecutiveOne(binary)}')
+
+
+print('Example 1:')
+solution([0, 1, 1, 0, 1, 1, 1])
+
+print('\nExample 2:')
+solution([0, 0, 0, 0])
+
+print('\nExample 3:')
+solution([1, 0, 1, 0, 1, 1])
+
+print('\nExample 4:')
+solution([1, 1, 1, 0, 1, 1, 0])
+
+print('\nExample 5:')
+solution([1, 0, 1, 1, 0, 1, 0])