Last active
November 16, 2017 10:53
-
-
Save bazwilliams/1c30692f0b0190936d80be54579f9039 to your computer and use it in GitHub Desktop.
Our mobbed solution to the Codor Dojo set at Python Glasgow (https://www.meetup.com/Python-Glasgow/events/244377303/)
This file contains 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 addUp(contribution): | |
return sum(contribution) / len(contribution) | |
def calculate_new_contribution(contribution, delta, involvement): | |
return contribution - delta if involvement else 0 | |
def calculate_overpayment(contribution, involvement): | |
d = addUp([c for c,i in zip(contribution, involvement) if i]) | |
return [calculate_new_contribution(c,d,i) for c,i in zip(contribution, involvement)] | |
def calculate_overpayments(contributions, involvements): | |
overpayments = [calculate_overpayment(c,i) for c, i in zip(contributions, involvements)] | |
return [round(sum(col),2) for col in zip(*overpayments)] | |
contributions =[ | |
[ 80.61, 0, 0, 0 ], | |
[ 0, 0, 0, 46.86 ], | |
[ 0, 71.75, 71.75, 0 ], | |
[ 0, 0, 0, 17.64 ], | |
[ 0 ,0, 0, 8], | |
[ 0, 0, 0, 18.45], | |
[ 0, 6.55,0, 0] | |
] | |
involvements = [ | |
[True, True, True, True], | |
[True, True, True, True], | |
[True, True, True, True], | |
[False, True, True, True], | |
[True, True, True, True], | |
[True, True, True, True], | |
[True, True, True, True], | |
] | |
print(calculate_overpayments(contributions, involvements)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Modified add_expense_entry() method to make data entry a little less tedious. I assume that using a for loop is ok for the data entry task.
Works for case where item is non-default and both float and bool elements are given, e.g [5.88,False], which would be an odd circumstance, paying for an expense in which you had no involvement.