Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mraarif/7d8c3951aea3067c66416082855e1370 to your computer and use it in GitHub Desktop.
Save mraarif/7d8c3951aea3067c66416082855e1370 to your computer and use it in GitHub Desktop.
This gist solves the problem of determining whether if given array can be divided into three non empty partitions and sum of those partitions is same.
def check_if_passes(input_array):
is_divisible = sum(input_array) % 3 == 0
if not is_divisible:
return is_divisible
chunk = sum(input_array) / 3
entries = []
addition = 0
for item in input_array:
addition = item + addition
if addition == chunk:
entries.append(addition)
addition = 0
return len(entries) == 3
my_array = [3, 3, 6, 5, -2, 2, 5, 1, -9, 4]
print("\nThe result is: {0}".format(check_if_passes(my_array)))
@mraarif
Copy link
Author

mraarif commented Sep 2, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment