Created
November 12, 2019 00:14
-
-
Save alacret/3cafd47b702182e9feef8bb6225d8cd0 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 divide_list(numbers): | |
half = len(numbers) // 2 | |
return numbers[:half], numbers[half:] | |
def add_lists(list_a, list_b): | |
if len(list_a) < len(list_b): | |
list_a.insert(0,0) | |
results = [] | |
for i in range(len(list_a)): | |
results.append(list_a[i] + list_b[i]) | |
return results | |
def split_and_add(numbers, n): | |
if len(numbers) == 1: | |
return numbers | |
for i in range(n): | |
a,b = divide_list(numbers) | |
numbers = add_lists(a,b) | |
return numbers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment