diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-05-31 21:33:17 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-31 21:33:17 +0100 |
| commit | 4945e504efdcde92d9df7153a7a4abcc2a916527 (patch) | |
| tree | 4d70a503369413c154f14f53b1fe4eaf976127f6 /challenge-115/stuart-little/python | |
| parent | 5339668b0eb9fc3dc3de93badfaea9ffaa2ecd0c (diff) | |
| parent | 91a046d22fdfe5f6b3216f90d31935badad986fc (diff) | |
| download | perlweeklychallenge-club-4945e504efdcde92d9df7153a7a4abcc2a916527.tar.gz perlweeklychallenge-club-4945e504efdcde92d9df7153a7a4abcc2a916527.tar.bz2 perlweeklychallenge-club-4945e504efdcde92d9df7153a7a4abcc2a916527.zip | |
Merge pull request #4178 from stuart-little/stuart-little_115_python
1st commit on 115_python
Diffstat (limited to 'challenge-115/stuart-little/python')
| -rwxr-xr-x | challenge-115/stuart-little/python/ch-1.py | 15 | ||||
| -rwxr-xr-x | challenge-115/stuart-little/python/ch-2.py | 8 |
2 files changed, 23 insertions, 0 deletions
diff --git a/challenge-115/stuart-little/python/ch-1.py b/challenge-115/stuart-little/python/ch-1.py new file mode 100755 index 0000000000..72c965394e --- /dev/null +++ b/challenge-115/stuart-little/python/ch-1.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python + +# run <script> <space-separated strings> + +import sys + +def canChain(words,start,end): + if len(words) == 0: + return 0 + if len(words) == 1: + return int(words[0][0] == start and words[0][-1] == end) + startIdxs = filter(lambda ix: words[ix][0] == start, range(len(words))) + return int(any(map(lambda ix: canChain([words[x] for x in range(len(words)) if x != ix], words[ix][-1], end), startIdxs))) + +print(0 if len(sys.argv) < 3 else canChain(sys.argv[2:], sys.argv[1][-1], sys.argv[1][0])) diff --git a/challenge-115/stuart-little/python/ch-2.py b/challenge-115/stuart-little/python/ch-2.py new file mode 100755 index 0000000000..9e6792f289 --- /dev/null +++ b/challenge-115/stuart-little/python/ch-2.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python + +# run <script> <space-separated digits> + +import re +import sys + +print(attemptedOut if (int(attemptedOut := re.sub(r"(.)([13579]*)$", r"\2\1", "".join(sorted(sys.argv[1:], reverse=True)))) % 2 == 0) else "No even digits..") |
