Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

space katem #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
23 changes: 20 additions & 3 deletions lib/max_subarray.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: ? o(n)
# Space Complexity: ? o(n)?
def max_sub_array(nums)
Comment on lines +2 to 4

Choose a reason for hiding this comment

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

👍

return 0 if nums == nil

raise NotImplementedError, "Method not implemented yet!"
current_sum = nums.first
max_number = nums.first

#use the spread here to loop through
(1...nums.length).each do |i|
current_sum += nums[i]
#check if current sum is larger than max, then max is the current num
if current_sum > max_number
max_number = current_sum
end
#if current sum is less than zero, then current zum equals 0
if current_sum < 0
current_sum = 0
end
end

return max_number

end
25 changes: 21 additions & 4 deletions lib/newman_conway.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@


# Time complexity: ?
# Space Complexity: ?
# Time complexity: ? o(n)
# Space Complexity: ? o(n)
def newman_conway(num)
Comment on lines +3 to 5

Choose a reason for hiding this comment

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

This works, with one bug.

raise NotImplementedError, "newman_conway isn't implemented"
end
raise ArgumentError if num <= 0
return 1 if num == 1

Choose a reason for hiding this comment

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

Because the method is supposed to return a string.

Suggested change
return 1 if num == 1
return "1" if num == 1


newman = [0, 1, 1]
goal = "1 1"
i = 3

#P(n) = P(P(n - 1)) + P(n - P(n - 1))
#https://www.geeksforgeeks.org/newman-conway-sequence/
until i >= num + 1
current_newman = newman[newman[i - 1]] + newman[i - (newman[i - 1])]

newman << current_newman
goal += " #{current_newman}"
i += 1
end

return goal
end