Created
April 14, 2017 16:13
-
-
Save Johnicholas/095c2f5f4aade60e695bfdbc65e19881 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def helper(a): | |
if len(a) == 0 | |
# base case | |
return 0, 0 | |
else: | |
# recursive case | |
best_prefix_total, best_span_total = helper(a[1:]) | |
# TODO | |
return foo, bar | |
# after getting this recursion working, then we would need to add memoization | |
def solve(a): | |
best_prefix_total, best_span_total = helper(a) | |
return best_span_total | |
def brute_force(a): | |
return max([sum(a[i:j]) for i in range(len(a)) for j in range(len(a)) if j - i >= 0]) | |
@given(st.lists(st.integers())) | |
def test_against_brute_force(self, a): | |
self.assertEqual(solve(a), brute_force(a)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment