aboutsummaryrefslogtreecommitdiff
path: root/challenge-325/roger-bell-west/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-325/roger-bell-west/python/ch-1.py')
-rwxr-xr-xchallenge-325/roger-bell-west/python/ch-1.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-325/roger-bell-west/python/ch-1.py b/challenge-325/roger-bell-west/python/ch-1.py
new file mode 100755
index 0000000000..87cc81ae31
--- /dev/null
+++ b/challenge-325/roger-bell-west/python/ch-1.py
@@ -0,0 +1,32 @@
+#! /usr/bin/python3
+
+def consecutiveone(a):
+ h = dict()
+ h[0] = 0
+ latch = 0
+ latched = False
+ for i, n in enumerate(a):
+ if n == 1 and not latched:
+ latched = True
+ latch = i
+ if n == 0 and latched:
+ latched = False
+ h[latch] = i - latch
+ if latched:
+ h[latch] = len(a) - latch
+ return max(h.values())
+
+import unittest
+
+class TestConsecutiveone(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(consecutiveone([0, 1, 1, 0, 1, 1, 1]), 3, 'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(consecutiveone([0, 0, 0, 0]), 0, 'example 2')
+
+ def test_ex3(self):
+ self.assertEqual(consecutiveone([1, 0, 1, 0, 1, 1]), 2, 'example 3')
+
+unittest.main()