aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-06-15 20:21:44 +0100
committerGitHub <noreply@github.com>2021-06-15 20:21:44 +0100
commit55561cd33408f541714ea6df242bcedb0126deb5 (patch)
tree735ebe82c47218912924b7adc5159c9befdfe7b4
parentaaf6bb0225f96064aceb72bc8ce074d0e538ea7f (diff)
parentb3e0d81b91d18703ea0453fde48dbe396159af22 (diff)
downloadperlweeklychallenge-club-55561cd33408f541714ea6df242bcedb0126deb5.tar.gz
perlweeklychallenge-club-55561cd33408f541714ea6df242bcedb0126deb5.tar.bz2
perlweeklychallenge-club-55561cd33408f541714ea6df242bcedb0126deb5.zip
Merge pull request #4264 from stuart-little/stuart-little_117_python
1st commit on 117_python
-rwxr-xr-xchallenge-117/stuart-little/python/ch-1.py11
-rwxr-xr-xchallenge-117/stuart-little/python/ch-2.py17
2 files changed, 28 insertions, 0 deletions
diff --git a/challenge-117/stuart-little/python/ch-1.py b/challenge-117/stuart-little/python/ch-1.py
new file mode 100755
index 0000000000..564846b10e
--- /dev/null
+++ b/challenge-117/stuart-little/python/ch-1.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+
+# run <script> <path-to-file>
+
+import re
+import sys
+
+with open(sys.argv[1], 'r') as f:
+ lns = f.readlines()
+
+print(int((len(lns)+2)*(len(lns)+1)/2) - sum([int(re.search(r"\d+", ln).group(0)) for ln in lns]))
diff --git a/challenge-117/stuart-little/python/ch-2.py b/challenge-117/stuart-little/python/ch-2.py
new file mode 100755
index 0000000000..89971728a9
--- /dev/null
+++ b/challenge-117/stuart-little/python/ch-2.py
@@ -0,0 +1,17 @@
+#!/usr/bin/env python
+
+# run <script> <number>
+
+import sys
+
+memo=[[''],['R','LH']]
+
+def mkPaths(size):
+ if size >= len(memo):
+ res = ['R' + x for x in mkPaths(size-1)]
+ res += ['L' + lft + 'H' + rght for nr in range(size) for lft in mkPaths(nr) for rght in mkPaths(size-1-nr)]
+ memo.append(res)
+ return memo[size]
+
+for pth in mkPaths(int(sys.argv[1])):
+ print(pth)