aboutsummaryrefslogtreecommitdiff
path: root/challenge-249/roger-bell-west/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-249/roger-bell-west/python/ch-1.py')
-rwxr-xr-xchallenge-249/roger-bell-west/python/ch-1.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-249/roger-bell-west/python/ch-1.py b/challenge-249/roger-bell-west/python/ch-1.py
new file mode 100755
index 0000000000..e086773409
--- /dev/null
+++ b/challenge-249/roger-bell-west/python/ch-1.py
@@ -0,0 +1,25 @@
+#! /usr/bin/python3
+
+def shortestdistance(a0):
+ if len(a0) % 2 != 0:
+ return []
+ a = a0
+ a.sort()
+ out = []
+ for i in range(0, len(a), 2):
+ if a[i] != a[i+1]:
+ return []
+ out.append([a[i], a[i]])
+ return out
+
+import unittest
+
+class TestShortestdistance(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(shortestdistance([3, 2, 3, 2, 2, 2]), [[2, 2], [2, 2], [3, 3]], 'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(shortestdistance([1, 2, 3, 4]), [], 'example 2')
+
+unittest.main()