-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoding_segment.txt
More file actions
67 lines (57 loc) · 1.31 KB
/
coding_segment.txt
File metadata and controls
67 lines (57 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""
fye@plaid.com
Bank to bank xfer
multiple txns b.w 2 banks, reduce total xfers per banks, send 1 instead of many
netting engine for hypothetical banks
26 banks, a,b,c,...
input xfers,
output xfers with net effect
Central Bank algorithm, Bank A is central bank
Input:
AB1
BA2
Output:
BA1
Input:
AB1
BA2
BC1
Net Balances:
A: 1
B: -2
C: 1
Franklin Ye3:11 PM
Output:
BA2
AC1
"""
# This method will calculate the net balance for each bank
def net_balance(input):
balance_dict = {
"A" : 0,
"B" : 0
}
for i in input:
bank1 = i[0]
bank2 = i[1]
value = int(i[2])
balance_dict[bank1] = int(balance_dict[bank1]) - value
balance_dict[bank2] = int(balance_dict[bank2]) + value
return balance_dict
# This method will perform the settling of the net balanced list
def settle(balance_dict):
print(balance_dict)
return_list =[]
for i in balance_dict:
if i != "A":
if balance_dict[i] < 0:
strVal = i+"A"+str(balance_dict[i]*-1)
else:
strVal = "A"+i+str((balance_dict[i]))
return_list.append(strVal)
return return_list
def cba(input):
balanced = net_balance(input)
return settle(balanced)
input = ["AB1", "BA2"]
print(cba(input))