-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbruteforce.py
30 lines (23 loc) · 964 Bytes
/
bruteforce.py
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
from itertools import combinations
import sys
from utils import time_it, load_shares
@time_it
def bruteforce(file_name: str):
shares = load_shares(file_name)
best_combination = None
gain_best_combination = 0
price_best_combination = 0
for rep in range(1, len(shares)+1):
for combination in combinations(shares, rep):
price_combination = sum(share['price'] for share in combination)
if price_combination <= 500:
gain_combination = sum(share['gain'] for share in combination)
if gain_combination > gain_best_combination:
best_combination = combination
gain_best_combination = gain_combination
price_best_combination = price_combination
print([share['name'] for share in best_combination])
print(gain_best_combination)
print(price_best_combination)
if __name__ == '__main__':
bruteforce(sys.argv[1])