-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBruteForce.py
39 lines (30 loc) · 965 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
31
32
33
34
35
36
37
38
39
def BruteKProposals(k, dates):
if len(dates) < k:
return None
return KProposals(k, dates, [False for i in dates], list())
def Fit(item, itemlist):
for prop in itemlist:
for i in item:
for j in prop:
if i == j:
return False
return True
def KProposals(k, dates, checkdates, taken):
if len(taken) == k:
return taken
for i in range(len(dates)):
if Fit(dates[i], taken) and not checkdates[i]:
newTaken = taken.copy()
newTaken.append(dates[i])
checkdates[i] = True
newcheck = checkdates.copy()
return KProposals(k, dates, newcheck, newTaken)
oldcheck = checkdates.copy()
return KProposals(k, dates, oldcheck, taken[:len(taken) - 1])
dates = [[1, 3, 2],
[6, 7, 8],
[2, 4, 5],
[7, 9, 10],
[3, 8, 10],
[11, 9, 12]]
print(BruteKProposals(3, dates))