aboutsummaryrefslogtreecommitdiff
path: root/challenge-285/packy-anderson/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-285/packy-anderson/python/ch-1.py')
-rwxr-xr-xchallenge-285/packy-anderson/python/ch-1.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-285/packy-anderson/python/ch-1.py b/challenge-285/packy-anderson/python/ch-1.py
new file mode 100755
index 0000000000..18d8eb136f
--- /dev/null
+++ b/challenge-285/packy-anderson/python/ch-1.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+
+def noConnection(routes):
+ starts = set([ x[0] for x in routes ])
+ ends = set([ x[1] for x in routes ])
+ noConnection = ends - starts
+ if len(noConnection) == 0:
+ return 'no terminal destinations'
+ if len(noConnection) > 1:
+ return 'multiple terminal destinations'
+ return list(noConnection)[0]
+
+def tupleJoin(listVar):
+ return ', '.join([
+ f'[{x[0]}, {x[1]}]' for x in listVar
+ ])
+
+def solution(routes):
+ print(f'Input: @routes = ({ tupleJoin(routes) })')
+ print(f'Output: {noConnection(routes)}')
+
+print('Example 1:')
+solution([["B","C"], ["D","B"], ["C","A"]])
+
+print('\nExample 2:')
+solution([["A","Z"], ])
+
+print('\nBad Input: multiple terminal destination')
+solution([["A","B"], ["C", "D"]])
+
+print('\nBad Input: no terminal destinations')
+solution([["A","Z"], ["Z", "A"]])