diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-04-19 23:28:30 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-19 23:28:30 +0100 |
| commit | 78b641b69a5133a9c8f79462f9ccda0f2f5b8595 (patch) | |
| tree | e2533fcc3492d70170c655b1768d35bed17bb6c8 | |
| parent | bb2f1a7bea02a486b41e446d7496630bf10341c2 (diff) | |
| parent | 2abf6310e945c12e3138493ac44004dc7e078196 (diff) | |
| download | perlweeklychallenge-club-78b641b69a5133a9c8f79462f9ccda0f2f5b8595.tar.gz perlweeklychallenge-club-78b641b69a5133a9c8f79462f9ccda0f2f5b8595.tar.bz2 perlweeklychallenge-club-78b641b69a5133a9c8f79462f9ccda0f2f5b8595.zip | |
Merge pull request #3930 from stuart-little/stuart-little_109_python
1st commit on 109_python
| -rwxr-xr-x | challenge-109/stuart-little/python/ch-1.py | 5 | ||||
| -rwxr-xr-x | challenge-109/stuart-little/python/ch-2.py | 21 |
2 files changed, 26 insertions, 0 deletions
diff --git a/challenge-109/stuart-little/python/ch-1.py b/challenge-109/stuart-little/python/ch-1.py new file mode 100755 index 0000000000..d6ffa21cf1 --- /dev/null +++ b/challenge-109/stuart-little/python/ch-1.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python + +# run <script> + +print("0, 0, 0, 2, 0, 5, 0, 6, 3, 7, 0, 15, 0, 9, 8, 14, 0, 20, 0, 21") diff --git a/challenge-109/stuart-little/python/ch-2.py b/challenge-109/stuart-little/python/ch-2.py new file mode 100755 index 0000000000..c0dfbf495d --- /dev/null +++ b/challenge-109/stuart-little/python/ch-2.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +# run <script> <space-separated numbers> + +from itertools import permutations +import string +import sys + +def sumsEqNr(nr,ar,bl): + if (len(ar) <= 3): + return bl and (nr == sum(ar)) + return sumsEqNr(nr,ar[2:],(bl and (nr == sum(ar[:3])))) + +def allSumsEq(ar): + return sumsEqNr(sum(ar[:2]),ar[1:],True) + +def pprnt(ar): + return "\nSolution: " + ", ".join([f"{c} = {v}" for (c,v) in list(zip(string.ascii_lowercase[:7],ar))]) + f"\nSum: {sum(ar[:2])}" + +sols = list(filter(allSumsEq,list(permutations(map(int, sys.argv[1:]))))) +print("No solution." if (not sols) else "\n".join(map(pprnt,sols))) |
