Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alacret/3cafd47b702182e9feef8bb6225d8cd0 to your computer and use it in GitHub Desktop.
Save alacret/3cafd47b702182e9feef8bb6225d8cd0 to your computer and use it in GitHub Desktop.
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