diff options
| -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..") |
