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/pokgopun/python/ch-2.py | |
| 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/pokgopun/python/ch-2.py')
| -rw-r--r-- | challenge-260/pokgopun/python/ch-2.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/challenge-260/pokgopun/python/ch-2.py b/challenge-260/pokgopun/python/ch-2.py new file mode 100644 index 0000000000..6925831197 --- /dev/null +++ b/challenge-260/pokgopun/python/ch-2.py @@ -0,0 +1,68 @@ +### https://theweeklychallenge.org/blog/perl-weekly-challenge-260/ +""" + +Task 2: Dictionary Rank + +Submitted by: [43]Mark Anderson + __________________________________________________________________ + + You are given a word, $word. + + Write a script to compute the dictionary rank of the given word. + +Example 1 + +Input: $word = 'CAT' +Output: 3 + +All possible combinations of the letters: +CAT, CTA, ATC, TCA, ACT, TAC + +Arrange them in alphabetical order: +ACT, ATC, CAT, CTA, TAC, TCA + +CAT is the 3rd in the list. +Therefore the dictionary rank of CAT is 3. + +Example 2 + +Input: $word = 'GOOGLE' +Output: 88 + +Example 3 + +Input: $word = 'SECRET' +Output: 255 + __________________________________________________________________ + + Last date to submit the solution 23:59 (UK Time) Sunday 17th March + 2024. + __________________________________________________________________ + +SO WHAT DO YOU THINK ? +""" +### solution by pokgopun@gmail.com + +from itertools import permutations + +def DC(word: str): + return tuple( + sorted( + set( + permutations(word,len(word)) + ) + ) + ).index(tuple(word)) + 1 + +import unittest + +class TestDC(unittest.TestCase): + def test(self): + for inpt, otpt in { + 'CAT': 3, + 'GOOGLE': 88, + 'SECRET': 255, + }.items(): + self.assertEqual(DC(inpt),otpt) + +unittest.main() |
