From 1a58ddd3b3e95987b3d91c5a183b7fec86749959 Mon Sep 17 00:00:00 2001 From: Juliana Ruiz Date: Sun, 17 Jul 2022 22:15:47 -0700 Subject: [PATCH 1/3] wave 1 --- .vscode/settings.json | 14 ++++++++++++++ lib/max_subarray.py | 15 ++++++++++++--- lib/newman_conway.py | 1 + 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6620bcd --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,14 @@ +{ + "python.testing.unittestArgs": [ + "-v", + "-s", + "./tests", + "-p", + "*test.py" + ], + "python.testing.pytestEnabled": true, + "python.testing.unittestEnabled": false, + "python.testing.pytestArgs": [ + "tests" + ] +} \ No newline at end of file diff --git a/lib/max_subarray.py b/lib/max_subarray.py index 4e892e0..124e313 100644 --- a/lib/max_subarray.py +++ b/lib/max_subarray.py @@ -2,11 +2,20 @@ def max_sub_array(nums): """ Returns the max subarray of the given list of numbers. Returns 0 if nums is None or an empty list. - Time Complexity: ? - Space Complexity: ? + Time Complexity: On + Space Complexity: ON """ if nums == None: return 0 if len(nums) == 0: return 0 - pass + + max_sub_array = nums[0] + max_sub = nums[0] + + for i in range(1,len(nums)): + + max_sub = max(max_sub + nums[i], nums[i]) + max_sub_array = max(max_sub_array, max_sub) + + return max_sub_array \ No newline at end of file diff --git a/lib/newman_conway.py b/lib/newman_conway.py index 70a3353..78810e8 100644 --- a/lib/newman_conway.py +++ b/lib/newman_conway.py @@ -8,3 +8,4 @@ def newman_conway(num): Space Complexity: ? """ pass + \ No newline at end of file From dd372e6134ce095c0cc7a0ae459c7bba157b6430 Mon Sep 17 00:00:00 2001 From: Juliana Ruiz Date: Sun, 17 Jul 2022 22:27:16 -0700 Subject: [PATCH 2/3] newman conway attempt --- lib/newman_conway.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/newman_conway.py b/lib/newman_conway.py index 78810e8..9980d98 100644 --- a/lib/newman_conway.py +++ b/lib/newman_conway.py @@ -7,5 +7,7 @@ def newman_conway(num): Time Complexity: ? Space Complexity: ? """ - pass - \ No newline at end of file + if num == 1 or num == 2: + return 1 + else: + return newman_conway(newman_conway(num - 1)) + newman_conway(num - newman_conway(num-1)) \ No newline at end of file From 739b64905addd1233d60c75cf447c79f1bf9fac3 Mon Sep 17 00:00:00 2001 From: Juliana Ruiz Date: Mon, 18 Jul 2022 21:41:14 -0700 Subject: [PATCH 3/3] passing all waves --- lib/newman_conway.py | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/newman_conway.py b/lib/newman_conway.py index 9980d98..a522a91 100644 --- a/lib/newman_conway.py +++ b/lib/newman_conway.py @@ -1,13 +1,32 @@ - +import array # Time complexity: ? # Space Complexity: ? def newman_conway(num): """ Returns a list of the Newman Conway numbers for the given value. - Time Complexity: ? - Space Complexity: ? + Time Complexity: o(n) + Space Complexity: o(n) """ - if num == 1 or num == 2: - return 1 - else: - return newman_conway(newman_conway(num - 1)) + newman_conway(num - newman_conway(num-1)) \ No newline at end of file + # to store values + if num < 1: + raise ValueError ("Invalid Num") + if num == 1: + return "1" + + f = [0, 1, 1] + output = "1" + + count = 3 + # To store values of sequence in array + + while count <= num: + f.append(f[f[count - 1]]+ f[count - f [ count -1]]) + count += 1 + number = [str(item) for item in f] + + return " ".join(number[1:]) + # for i in range(3, num + 1): + # r = f[f[i-1]]+f[i-f[i-1]] + # f.append(r); + + # return r \ No newline at end of file