From 2a794c10fcef990387de404d7da5f74925451d61 Mon Sep 17 00:00:00 2001 From: Packy Anderson Date: Mon, 2 Sep 2024 23:39:32 -0400 Subject: 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 --- challenge-285/packy-anderson/python/ch-1.py | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 challenge-285/packy-anderson/python/ch-1.py (limited to 'challenge-285/packy-anderson/python/ch-1.py') 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"]]) -- cgit