Last active
August 29, 2015 14:16
-
-
Save montaro/a187932a620ae0cf7b50 to your computer and use it in GitHub Desktop.
Revisions
-
montaro revised this gist
Mar 8, 2015 . 1 changed file with 5 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,13 +5,14 @@ def list_equilibrium(l): s = sum(l) right_sum = s left_sum = 0 for i in range(len(l)): elem = l[i] right_sum = right_sum - elem if right_sum == left_sum: print "The Equilibrium Index is: ", i, "for list: ", l return i left_sum = left_sum + elem print "There is no Equilibrium Index for list: ", l return None -
montaro created this gist
Mar 8, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ __author__ = 'arefaey' def list_equilibrium(l): s = sum(l) right_sum = s left_sum = 0 for elem in l: right_sum = right_sum - elem if right_sum == left_sum: print("The Equilibrium Index is: ", elem, "for list: ", l) return elem left_sum = left_sum + elem print("There is no Equilibrium Index for list: ", l) return None l0 = [] l1 = [1] l2 = [1, 2] l3 = [1, 2, 1] l4 = [1, 2, 1, -3, -4, 3, 5, 22, 1, 7, -2, -1] test_lists = [l0, l1, l2, l3, l4] for l in test_lists: list_equilibrium(l)