From 0baf4cc2532855717eb71a66accd6c54471cee0d Mon Sep 17 00:00:00 2001 From: wilson-romero Date: Fri, 22 May 2020 09:55:45 -0500 Subject: [PATCH 1/9] [solution] challenge python 9 --- solutions/wilson_romero/__init__.py | 0 solutions/wilson_romero/solution.py | 13 +++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 solutions/wilson_romero/__init__.py create mode 100644 solutions/wilson_romero/solution.py diff --git a/solutions/wilson_romero/__init__.py b/solutions/wilson_romero/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/solutions/wilson_romero/solution.py b/solutions/wilson_romero/solution.py new file mode 100644 index 0000000..2f15405 --- /dev/null +++ b/solutions/wilson_romero/solution.py @@ -0,0 +1,13 @@ +from typing import List + + +class Solution: + + def duplicate_zeros(self, arr: List[int]): + # AQUÍ VA TU SOLUCIÓN + indices = list(filter(lambda x: arr[x] == 0, range(len(arr)))) + shift = 0 + for i in indices: + arr.insert(i + shift, 0) + arr.pop() + shift = shift + 1 From 6990d468ae84b6ad2ff8f024fda6629fa748fd43 Mon Sep 17 00:00:00 2001 From: wilson-romero Date: Fri, 22 May 2020 13:17:32 -0500 Subject: [PATCH 2/9] [correction] challenge python 9 --- solutions/wilson_romero/solution.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/solutions/wilson_romero/solution.py b/solutions/wilson_romero/solution.py index 2f15405..3d76a63 100644 --- a/solutions/wilson_romero/solution.py +++ b/solutions/wilson_romero/solution.py @@ -1,13 +1,18 @@ +""" Module solution """ from typing import List - class Solution: - + """ Challenge solution """ def duplicate_zeros(self, arr: List[int]): - # AQUÍ VA TU SOLUCIÓN - indices = list(filter(lambda x: arr[x] == 0, range(len(arr)))) - shift = 0 - for i in indices: - arr.insert(i + shift, 0) - arr.pop() - shift = shift + 1 + """ Modify the list by doubling the zeros and correcting the items to the right. """ + next_index = 0 + length = len(arr) + while True: + try: + next_index = arr.index(0, next_index) + arr.insert(next_index + 1, 0) + arr.pop() + next_index = next_index + 2 + except ValueError: + break + arr = arr[:length] From 262366462197615b7171a6da64cc426ad97f0961 Mon Sep 17 00:00:00 2001 From: wilson-romero Date: Fri, 22 May 2020 13:23:15 -0500 Subject: [PATCH 3/9] [correction] challenge python 9 --- solutions/wilson_romero/solution.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/wilson_romero/solution.py b/solutions/wilson_romero/solution.py index 3d76a63..d9aeaea 100644 --- a/solutions/wilson_romero/solution.py +++ b/solutions/wilson_romero/solution.py @@ -4,7 +4,7 @@ class Solution: """ Challenge solution """ def duplicate_zeros(self, arr: List[int]): - """ Modify the list by doubling the zeros and correcting the items to the right. """ + """Duplicate zeros and shift right""" next_index = 0 length = len(arr) while True: From edf934c946c065e10e79930f00d5704fb9adc5c7 Mon Sep 17 00:00:00 2001 From: wilson-romero Date: Sat, 23 May 2020 15:58:45 -0500 Subject: [PATCH 4/9] New submission - wilson-romero --- main.py | 19 +++++++++++++++++++ solutions/wilson_romero/solution.py | 18 +++++++----------- 2 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..b2d5416 --- /dev/null +++ b/main.py @@ -0,0 +1,19 @@ + +from typing import List + + +def duplicate_zeros(arr: List[int]): + # AQUÍ VA TU SOLUCIÓN + index = 0 + start = 0 + for step, value in enumerate(arr): + if value == 0 and step >= index: + print(step, value, index) + arr[step + 1:] = arr[step:-1] + index = step + 2 + + +if __name__ == "__main__": + arr = [1, 0, 2, 3, 0, 4, 5, 0] + duplicate_zeros(arr) + print(arr) diff --git a/solutions/wilson_romero/solution.py b/solutions/wilson_romero/solution.py index d9aeaea..2081974 100644 --- a/solutions/wilson_romero/solution.py +++ b/solutions/wilson_romero/solution.py @@ -1,18 +1,14 @@ """ Module solution """ from typing import List + class Solution: """ Challenge solution """ + def duplicate_zeros(self, arr: List[int]): """Duplicate zeros and shift right""" - next_index = 0 - length = len(arr) - while True: - try: - next_index = arr.index(0, next_index) - arr.insert(next_index + 1, 0) - arr.pop() - next_index = next_index + 2 - except ValueError: - break - arr = arr[:length] + index = 0 + for step, value in enumerate(arr): + if value == 0 and step >= index: + arr[step + 1:] = arr[step:-1] + index = step + 2 From f726f1a2622c8ef82e10b7999434843ceb8afbf2 Mon Sep 17 00:00:00 2001 From: wilson-romero Date: Sat, 23 May 2020 16:00:46 -0500 Subject: [PATCH 5/9] New submission - wilson-romero --- main.py | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 main.py diff --git a/main.py b/main.py deleted file mode 100644 index b2d5416..0000000 --- a/main.py +++ /dev/null @@ -1,19 +0,0 @@ - -from typing import List - - -def duplicate_zeros(arr: List[int]): - # AQUÍ VA TU SOLUCIÓN - index = 0 - start = 0 - for step, value in enumerate(arr): - if value == 0 and step >= index: - print(step, value, index) - arr[step + 1:] = arr[step:-1] - index = step + 2 - - -if __name__ == "__main__": - arr = [1, 0, 2, 3, 0, 4, 5, 0] - duplicate_zeros(arr) - print(arr) From 83259b81796267d7818dce35571965b66cb261af Mon Sep 17 00:00:00 2001 From: wilson-romero Date: Mon, 25 May 2020 21:35:48 -0500 Subject: [PATCH 6/9] Fix solution with zeros null or full zeros --- solutions/wilson_romero/solution.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/solutions/wilson_romero/solution.py b/solutions/wilson_romero/solution.py index 2081974..9e8c69a 100644 --- a/solutions/wilson_romero/solution.py +++ b/solutions/wilson_romero/solution.py @@ -7,8 +7,13 @@ class Solution: def duplicate_zeros(self, arr: List[int]): """Duplicate zeros and shift right""" - index = 0 + length = len(arr) + zeros = [] for step, value in enumerate(arr): - if value == 0 and step >= index: - arr[step + 1:] = arr[step:-1] - index = step + 2 + if value == 0: + zeros.append(step) + + length_zeros = len(zeros) + if length_zeros > 0 and length_zeros < length: + for step, value in enumerate(zeros): + arr[value + 1:] = arr[value:-1] From 84e44214a1e44f247360329b986a0380ba21b04f Mon Sep 17 00:00:00 2001 From: wilson-romero Date: Mon, 25 May 2020 23:18:03 -0500 Subject: [PATCH 7/9] fix solution --- .gitignore | 3 ++- solutions/wilson_romero/solution.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index b33d783..6e17493 100644 --- a/.gitignore +++ b/.gitignore @@ -129,4 +129,5 @@ dmypy.json .pyre/ # VSCode -.vscode/ \ No newline at end of file +.vscode/ +main.py diff --git a/solutions/wilson_romero/solution.py b/solutions/wilson_romero/solution.py index 9e8c69a..ef89089 100644 --- a/solutions/wilson_romero/solution.py +++ b/solutions/wilson_romero/solution.py @@ -16,4 +16,6 @@ def duplicate_zeros(self, arr: List[int]): length_zeros = len(zeros) if length_zeros > 0 and length_zeros < length: for step, value in enumerate(zeros): - arr[value + 1:] = arr[value:-1] + # print(step, value) + arr[value + step + 1:] = arr[value + step:-1] + # print("c:", arr) From 187291f87f05b4f0575bae7c430f1a8076ef0bca Mon Sep 17 00:00:00 2001 From: wilson-romero Date: Tue, 26 May 2020 00:08:52 -0500 Subject: [PATCH 8/9] remove comments --- solutions/wilson_romero/solution.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/solutions/wilson_romero/solution.py b/solutions/wilson_romero/solution.py index ef89089..32a8680 100644 --- a/solutions/wilson_romero/solution.py +++ b/solutions/wilson_romero/solution.py @@ -16,6 +16,5 @@ def duplicate_zeros(self, arr: List[int]): length_zeros = len(zeros) if length_zeros > 0 and length_zeros < length: for step, value in enumerate(zeros): - # print(step, value) arr[value + step + 1:] = arr[value + step:-1] - # print("c:", arr) + \ No newline at end of file From b6400bfecf2a97643c0ef703c9c1ada1fc3f2801 Mon Sep 17 00:00:00 2001 From: wilson-romero Date: Tue, 26 May 2020 00:13:03 -0500 Subject: [PATCH 9/9] fix pylint errors --- solutions/wilson_romero/solution.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/solutions/wilson_romero/solution.py b/solutions/wilson_romero/solution.py index 32a8680..d4aca88 100644 --- a/solutions/wilson_romero/solution.py +++ b/solutions/wilson_romero/solution.py @@ -14,7 +14,6 @@ def duplicate_zeros(self, arr: List[int]): zeros.append(step) length_zeros = len(zeros) - if length_zeros > 0 and length_zeros < length: + if 0 < length_zeros < length: for step, value in enumerate(zeros): arr[value + step + 1:] = arr[value + step:-1] - \ No newline at end of file