diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2021-06-14 13:13:07 -0400 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2021-06-14 13:13:07 -0400 |
| commit | b3e0d81b91d18703ea0453fde48dbe396159af22 (patch) | |
| tree | 3a6f61add6f3d220be7a2e1be31450169086d127 | |
| parent | dad6bcabbefc743b091695a82fcfb92342397e38 (diff) | |
| download | perlweeklychallenge-club-b3e0d81b91d18703ea0453fde48dbe396159af22.tar.gz perlweeklychallenge-club-b3e0d81b91d18703ea0453fde48dbe396159af22.tar.bz2 perlweeklychallenge-club-b3e0d81b91d18703ea0453fde48dbe396159af22.zip | |
1st commit on 117_python
| -rwxr-xr-x | challenge-117/stuart-little/python/ch-1.py | 11 | ||||
| -rwxr-xr-x | challenge-117/stuart-little/python/ch-2.py | 17 |
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) |
