diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2023-09-20 14:46:46 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-20 14:46:46 +0100 |
| commit | a9775defb11889f96970bccddd492302206551a7 (patch) | |
| tree | f561ce951cd83bc20018398ef8cb3598467edb2b | |
| parent | fe6fcae9cf6a18b1fdcb2067432e48164076a39a (diff) | |
| parent | 467af61204a3f9c222c334f2af937cf62c03977e (diff) | |
| download | perlweeklychallenge-club-a9775defb11889f96970bccddd492302206551a7.tar.gz perlweeklychallenge-club-a9775defb11889f96970bccddd492302206551a7.tar.bz2 perlweeklychallenge-club-a9775defb11889f96970bccddd492302206551a7.zip | |
Merge pull request #8737 from oWnOIzRi/week235
add solutions week 235 in python
| -rw-r--r-- | challenge-235/steven-wilson/python/ch-01.py | 25 | ||||
| -rw-r--r-- | challenge-235/steven-wilson/python/ch-02.py | 32 |
2 files changed, 57 insertions, 0 deletions
diff --git a/challenge-235/steven-wilson/python/ch-01.py b/challenge-235/steven-wilson/python/ch-01.py new file mode 100644 index 0000000000..4d5a26bae5 --- /dev/null +++ b/challenge-235/steven-wilson/python/ch-01.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + + +def remove_one(elements): + """removing ONLY one integer makes it strictly increasing order + >>> remove_one( [0, 2, 9, 4, 6] ) + True + >>> remove_one( [5, 1, 3, 2] ) + False + >>> remove_one( [2, 2, 3] ) + True + """ + remove = 0 + for i in range(len(elements) - 1): + if(elements[i] > elements[i+1]): + remove += 1 + if remove == 2: + return False + return True + + +if __name__ == "__main__": + import doctest + + doctest.testmod() diff --git a/challenge-235/steven-wilson/python/ch-02.py b/challenge-235/steven-wilson/python/ch-02.py new file mode 100644 index 0000000000..9a5586206e --- /dev/null +++ b/challenge-235/steven-wilson/python/ch-02.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + + +def duplicate_zero(elements): + '''duplicate each occurrence of ZERO in the given array and shift + the remaining to the right but make sure the size of array remain + the same + >>> duplicate_zero( [1, 0, 2, 3, 0, 4, 5, 0] ) + [1, 0, 0, 2, 3, 0, 0, 4] + >>> duplicate_zero( [1, 2, 3] ) + [1, 2, 3] + >>> duplicate_zero( [0, 3, 0, 4, 5] ) + [0, 0, 3, 0, 0] + >>> duplicate_zero( [1, 2, 3, 0] ) + [1, 2, 3, 0] + ''' + duplicate_zeroes = [] + elements_length = len(elements) + for i in range(elements_length): + if(elements[i] == 0): + duplicate_zeroes.extend([0,0]) + else: + duplicate_zeroes.append(elements[i]) + if len(duplicate_zeroes) >= elements_length: + break + return duplicate_zeroes[:elements_length] + + +if __name__ == "__main__": + import doctest + + doctest.testmod() |
