diff options
| author | rir <rirans@comcast.net> | 2024-03-16 20:07:25 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-16 20:07:25 -0400 |
| commit | ff5e8ece15a2384fbfb530710f10aa485017d4a5 (patch) | |
| tree | 6fe268d9ceb2b25a2951ea984c077450feb2efae /challenge-260/zapwai/python | |
| parent | 60f1003122fbada697317d943c238593f86db579 (diff) | |
| parent | 62e7fc3bb85a74125663f4fbd0a5911f6f30c81f (diff) | |
| download | perlweeklychallenge-club-ff5e8ece15a2384fbfb530710f10aa485017d4a5.tar.gz perlweeklychallenge-club-ff5e8ece15a2384fbfb530710f10aa485017d4a5.tar.bz2 perlweeklychallenge-club-ff5e8ece15a2384fbfb530710f10aa485017d4a5.zip | |
Merge branch 'manwar:master' into work
Diffstat (limited to 'challenge-260/zapwai/python')
| -rw-r--r-- | challenge-260/zapwai/python/ch-1.py | 27 | ||||
| -rw-r--r-- | challenge-260/zapwai/python/ch-2.py | 34 |
2 files changed, 61 insertions, 0 deletions
diff --git a/challenge-260/zapwai/python/ch-1.py b/challenge-260/zapwai/python/ch-1.py new file mode 100644 index 0000000000..4de8664aea --- /dev/null +++ b/challenge-260/zapwai/python/ch-1.py @@ -0,0 +1,27 @@ +def has_uniq_freq(l): + freq = {} + for item in l: + if item in freq.keys(): + freq[item] += 1 + else: + freq[item] = 1 + gq = {} + for v in freq.values(): + if v in gq.keys(): + gq[v] += 1 + else: + gq[v] = 0 + for v in gq.values(): + if v > 1: + return 0 + return 1 + +def proc(l): + print("Input:", l); + print("Output:", has_uniq_freq(l)) + +l1 = [1,2,2,1,1,3] +l2 = [1,2,3] +l3 = [-2,0,1,-2,1,1,0,1,-2,9] +for l in [l1, l2, l3]: + proc(l) diff --git a/challenge-260/zapwai/python/ch-2.py b/challenge-260/zapwai/python/ch-2.py new file mode 100644 index 0000000000..bdfe08eca0 --- /dev/null +++ b/challenge-260/zapwai/python/ch-2.py @@ -0,0 +1,34 @@ +def seek_word(word, sorts): + for i in range(len(sorts)): + if sorts[i] == word: + return i + return -1 + +def L(k, mylist, h): + if k == 1: + h[''.join(mylist)] = 1 + else: + L(k-1, mylist, h) + for i in range(k-1): + if k % 2 == 0: + swap(i, k-1, mylist) + else: + swap(0, k-1, mylist) + L(k-1, mylist, h) + +def swap(i, j, mylist): + tmp = mylist[i] + mylist[i] = mylist[j] + mylist[j] = tmp + +def proc(word): + perms = {} + print("Input:", word) + let = list(word) + L(len(word), let, perms) + sorts = sorted(perms.keys()) + print("Output", 1 + seek_word(word, sorts)) + +proc("CAT") +proc("GOGGLE") +proc("SECRET") |
