From 8642baafc2b599a1822f519c8aa908cceb1d187d Mon Sep 17 00:00:00 2001 From: Andrew Fulton Date: Mon, 21 Nov 2016 21:04:21 -0700 Subject: [PATCH 1/3] completed coding assessment --- EquilibriumIndex.py | 19 ++++++++++++++++++- TrueBooj.py | 14 +++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/EquilibriumIndex.py b/EquilibriumIndex.py index b691b90..5974e4c 100644 --- a/EquilibriumIndex.py +++ b/EquilibriumIndex.py @@ -1,2 +1,19 @@ def eqindex(data): - #do code here + ''' + a generator function that returns the equilibruim indices of a given list + ''' + + # get the sums of the reversed data list (data[-1], data[-1] + data[-2+], + # data[-1] + data[-2] + data[-3], ect.) + bw_sums = [sum(data[::-1][:i+1]) for i, x in enumerate(data[::-1])] + # initialize a value to hold the sums of the values + sums = 0 + # loop through each value in the list + for i, n in enumerate(data): + # add the value to the sums variable + sums += n + # check if sums is in backwards sum list, excluding the reverse index + # and higher of the initial list + if sums in bw_sums[:-(i+1)]: + # add one so the first value is indexed at 1 rather than zero + yield i + 1 diff --git a/TrueBooj.py b/TrueBooj.py index 4b558b4..56aa77b 100644 --- a/TrueBooj.py +++ b/TrueBooj.py @@ -1,2 +1,14 @@ def truebooj(number): - # do code here + ''' + function to return a number, or a string depending on if the remainder of + the number argument divided by 3, 5, or 10 is = to 0 + ''' + + if number % 10 == 0: + return 'TrueBooj' + elif number % 5 == 0: + return 'Booj' + elif number % 3 == 0: + return 'True' + else: + return str(number) From 3cecff20577c7217db2ac2cb75128c7ee59d5379 Mon Sep 17 00:00:00 2001 From: Andrew Fulton Date: Mon, 21 Nov 2016 21:12:50 -0700 Subject: [PATCH 2/3] fixed up comments --- EquilibriumIndex.py | 3 ++- TrueBooj.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/EquilibriumIndex.py b/EquilibriumIndex.py index 5974e4c..23eada5 100644 --- a/EquilibriumIndex.py +++ b/EquilibriumIndex.py @@ -15,5 +15,6 @@ def eqindex(data): # check if sums is in backwards sum list, excluding the reverse index # and higher of the initial list if sums in bw_sums[:-(i+1)]: - # add one so the first value is indexed at 1 rather than zero + # add one so indeces ar x[1], x[2], ... x[n] rather than + # x[0], x[1], ... x[n-1] yield i + 1 diff --git a/TrueBooj.py b/TrueBooj.py index 56aa77b..0590b15 100644 --- a/TrueBooj.py +++ b/TrueBooj.py @@ -1,7 +1,7 @@ def truebooj(number): ''' function to return a number, or a string depending on if the remainder of - the number argument divided by 3, 5, or 10 is = to 0 + the number argument divided by 3, 5, or 10 is = 0 ''' if number % 10 == 0: From 45fbaf520e59979eed4597138cd42e54178516ad Mon Sep 17 00:00:00 2001 From: Andrew Fulton Date: Mon, 21 Nov 2016 21:13:57 -0700 Subject: [PATCH 3/3] more comment edits --- EquilibriumIndex.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EquilibriumIndex.py b/EquilibriumIndex.py index 23eada5..b2395b6 100644 --- a/EquilibriumIndex.py +++ b/EquilibriumIndex.py @@ -15,6 +15,6 @@ def eqindex(data): # check if sums is in backwards sum list, excluding the reverse index # and higher of the initial list if sums in bw_sums[:-(i+1)]: - # add one so indeces ar x[1], x[2], ... x[n] rather than + # add one so indices ar x[1], x[2], ... x[n] rather than # x[0], x[1], ... x[n-1] yield i + 1