aboutsummaryrefslogtreecommitdiff
path: root/challenge-285/packy-anderson/python/ch-1.py
diff options
context:
space:
mode:
authorPacky Anderson <packy@cpan.org>2024-09-02 23:39:32 -0400
committerPacky Anderson <packy@cpan.org>2024-09-02 23:39:32 -0400
commit2a794c10fcef990387de404d7da5f74925451d61 (patch)
treeaa6bcbf898849e95f3950a989902155ed28df841 /challenge-285/packy-anderson/python/ch-1.py
parent0512711fccf91c731495f1dd901349cc900ec299 (diff)
downloadperlweeklychallenge-club-2a794c10fcef990387de404d7da5f74925451d61.tar.gz
perlweeklychallenge-club-2a794c10fcef990387de404d7da5f74925451d61.tar.bz2
perlweeklychallenge-club-2a794c10fcef990387de404d7da5f74925451d61.zip
Challenge 285 solutions by Packy Anderson
* Raku that maybe looks like Raku, but mostly like Perl * Perl * Python that definitely looks like Perl * Elixir 1 Blog post
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"]])