aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyler Wardhaugh <twardhaugh@cap-rx.com>2021-09-24 17:20:59 -0700
committerTyler Wardhaugh <twardhaugh@cap-rx.com>2021-09-24 17:20:59 -0700
commitfe8bbd71a8a390ef6faf85ce691d1eea6266ea5b (patch)
tree701acae1a1e6c85fa769367d23965f09d59aee07
parent0517bb51e461f35b7c7d8c22921b906d6e46256e (diff)
downloadperlweeklychallenge-club-fe8bbd71a8a390ef6faf85ce691d1eea6266ea5b.tar.gz
perlweeklychallenge-club-fe8bbd71a8a390ef6faf85ce691d1eea6266ea5b.tar.bz2
perlweeklychallenge-club-fe8bbd71a8a390ef6faf85ce691d1eea6266ea5b.zip
Ch131 (Python): Task 1
-rwxr-xr-xchallenge-131/tyler-wardhaugh/python/ch-1.py42
l---------challenge-131/tyler-wardhaugh/python/ch1.py1
-rwxr-xr-xchallenge-131/tyler-wardhaugh/python/test_ch1.py25
3 files changed, 68 insertions, 0 deletions
diff --git a/challenge-131/tyler-wardhaugh/python/ch-1.py b/challenge-131/tyler-wardhaugh/python/ch-1.py
new file mode 100755
index 0000000000..b59141f114
--- /dev/null
+++ b/challenge-131/tyler-wardhaugh/python/ch-1.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python3
+"""Challenge 131, Task 1"""
+
+import sys
+
+
+DEFAULT_INPUT = [[1, 2, 3, 6, 7, 8, 9]]
+
+
+def consecutive_arrays(coll: list[int]) -> list[list[int]]:
+ if not coll:
+ return [[]]
+
+ results = []
+ prev = coll[0]
+ for v in coll:
+ if prev + 1 != v:
+ results.append([])
+ results[-1].append(v)
+ prev = v
+
+ return results
+
+
+def main(args: list[str] = None) -> None:
+ """Run the task"""
+ if args is None:
+ args = sys.argv[1:]
+
+ coll = None
+ if args:
+ import json
+ coll = json.loads(args[0])
+ else:
+ coll = DEFAULT_INPUT[0]
+
+ results = consecutive_arrays(coll)
+ print(f'({str(results)[1:-1]})')
+
+
+if __name__ == '__main__':
+ sys.exit(main())
diff --git a/challenge-131/tyler-wardhaugh/python/ch1.py b/challenge-131/tyler-wardhaugh/python/ch1.py
new file mode 120000
index 0000000000..7680b02e4f
--- /dev/null
+++ b/challenge-131/tyler-wardhaugh/python/ch1.py
@@ -0,0 +1 @@
+ch-1.py \ No newline at end of file
diff --git a/challenge-131/tyler-wardhaugh/python/test_ch1.py b/challenge-131/tyler-wardhaugh/python/test_ch1.py
new file mode 100755
index 0000000000..87a0e71ef8
--- /dev/null
+++ b/challenge-131/tyler-wardhaugh/python/test_ch1.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python3
+"""Test Task 1"""
+
+import unittest
+from ch1 import consecutive_arrays
+
+
+class TestTask1(unittest.TestCase):
+ """Test Task 1"""
+
+ def test_example_cases(self):
+ """Test Task 1"""
+ self.assertEqual([[1, 2, 3], [6, 7, 8, 9]],
+ consecutive_arrays([1, 2, 3, 6, 7, 8, 9]))
+ self.assertEqual([[11, 12], [14], [17, 18, 19]],
+ consecutive_arrays([11, 12, 14, 17, 18, 19]))
+ self.assertEqual([[2], [4], [6], [8]],
+ consecutive_arrays([2, 4, 6, 8]))
+ self.assertEqual([[1, 2, 3, 4, 5]],
+ consecutive_arrays([1, 2, 3, 4, 5]))
+
+
+
+if __name__ == '__main__':
+ unittest.main()