Commit 2384e917 authored by Mikkel Wienberg Madsen's avatar Mikkel Wienberg Madsen 👀
Browse files

Cheesy

parent 38179269
Pipeline #21909 passed with stages
in 2 minutes and 30 seconds
......@@ -80,18 +80,20 @@ func MaxSubset(t int, superset []BallotList) map[string]bool {
combis := combin.Combinations(n, t)
log.Printf("N: %d, combis: %d\n", n, len(combis))
subsets := make([]map[string]bool, len(combis), n)
max := 0
best := len(Union(superset))
for i, ls := range combis {
sets := make([]BallotList, 0, len(ls))
for _, i := range ls {
sets = append(sets, superset[i])
}
subsets[i] = Intersection(sets)
}
max := 0
for i := 0; i < len(subsets); i++ {
if len(subsets[i]) > max {
max = i
}
if len(subsets[i]) == best {
break
}
}
return subsets[max]
}
......@@ -112,3 +114,13 @@ func Intersection(superset []BallotList) map[string]bool {
}
return set
}
func Union(superset []BallotList) map[string]bool {
union := make(map[string]bool)
for _, set := range superset {
for hash := range set {
union[hash] = true
}
}
return union
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment