diff options
| author | Packy Anderson <packy@cpan.org> | 2024-02-16 01:14:32 -0500 |
|---|---|---|
| committer | Packy Anderson <packy@cpan.org> | 2024-02-16 01:14:32 -0500 |
| commit | d23fbdd681ca2a9b02c5cb2234caa61d5ec32cef (patch) | |
| tree | 5a60957ab7b6f8f3907682e982d9ce5560ee29e8 /challenge-256/packy-anderson/python/ch-1.py | |
| parent | c9792b8a02f80c49e9bb4f0a1056c98d41e693a4 (diff) | |
| download | perlweeklychallenge-club-d23fbdd681ca2a9b02c5cb2234caa61d5ec32cef.tar.gz perlweeklychallenge-club-d23fbdd681ca2a9b02c5cb2234caa61d5ec32cef.tar.bz2 perlweeklychallenge-club-d23fbdd681ca2a9b02c5cb2234caa61d5ec32cef.zip | |
Challenge 256 solutions by Packy Anderson
* Raku
* Perl
* Python
1 Blog post
Diffstat (limited to 'challenge-256/packy-anderson/python/ch-1.py')
| -rwxr-xr-x | challenge-256/packy-anderson/python/ch-1.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/challenge-256/packy-anderson/python/ch-1.py b/challenge-256/packy-anderson/python/ch-1.py new file mode 100755 index 0000000000..d5aab629f4 --- /dev/null +++ b/challenge-256/packy-anderson/python/ch-1.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +def maximumPairs(words): + count = 0 + while words: + # the the first word off the list + first = words.pop(0) + # now compare to the rest of the words in the list + for i in range(len(words)): + second = words[i] + if first == second[::-1]: + # we found a pair + count += 1 + # remove words[i] from the list + words.pop(i) + # we don't need to compare + # any more words to first + break + return count + +def comma_join(arr): + return '", "'.join(arr) + +def solution(words): + print(f'Input: @words = ({words})') + count = maximumPairs(words) + print(f'Output: {count}') + +print('Example 1:') +solution(["ab", "de", "ed", "bc"]) + +print('\nExample 2:') +solution(["aa", "ba", "cd", "ed"]) + +print('\nExample 3:') +solution(["uv", "qp", "st", "vu", "mn", "pq"]) |
