Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ for all n > 2
P(n) = P(P(n - 1)) + P(n - P(n - 1))
```

Given a number n then print n terms of Newman-Conway Sequence
For a given a number: n
print n terms of Newman-Conway Sequence

Examples:

Expand Down
17 changes: 14 additions & 3 deletions lib/max_subarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@
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: O(n)
Space Complexity: O(1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"""
if nums == None:
return 0
if len(nums) == 0:
return 0
pass
if len(nums) == 1:
return nums[0]
max_sum = nums[0]
current_sum = nums[0]
for i in range(1, len(nums)):
if current_sum + nums[i] > nums[i]:
current_sum += nums[i]
else:
current_sum = nums[i]
if current_sum > max_sum:
max_sum = current_sum
return max_sum
40 changes: 35 additions & 5 deletions lib/newman_conway.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,40 @@

# # P(1) = 1
# # P(2) = 1
# # for all n > 2
# # P(n) = P(P(n - 1)) + P(n - P(n - 1))

# for i in range(2, num + 1):
# new_nc_num = nc_nums[nc_nums[i - 1]] + nc_nums[i - nc_nums[i - 1]]
# nc_nums.append(new_nc_num)


# string_list = []
# for n in nc_nums:
# string_list.append(str(n))

def sequence(num):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😎 Nice job also implementing a recursive version

if num == 1 or num == 2:
return 1
else:
return sequence(sequence(num-1)) + sequence(num -sequence(num-1))

# 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 Comnewmanslexity: O(n)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😎 Nice work on the Comnewmanslexity!

Space Complexity: O(n)
"""
pass

nc_nums = [1, 1]

if num < 1:
raise ValueError("Num must be greater than 0.")

for i in range(2, num + 1):
nc_nums.append(nc_nums[nc_nums[i - 1] - 1] + nc_nums[i - nc_nums[i - 1]])

string_list = []
for n in nc_nums:
string_list.append(str(n))

return " ".join(string_list[0:num])