Commit 0b5a2486 authored by Mikkel Wienberg Madsen's avatar Mikkel Wienberg Madsen 👀
Browse files

Fix max subset

parent b0cc5bda
Pipeline #21716 failed with stages
in 14 seconds
......@@ -61,10 +61,10 @@ func (j *Judge) GoodIds() []uuid.UUID {
return good
}
func MaxSubset(t int, superset [][]uuid.UUID) []uuid.UUID {
func MaxSubset(t int, superset [][]uuid.UUID) map[uuid.UUID]bool {
n := len(superset)
combis := combin.Combinations(t, n)
subsets := make([][]uuid.UUID, len(combis), n)
combis := combin.Combinations(n, t)
subsets := make([]map[uuid.UUID]bool, len(combis), n)
for i, ls := range combis {
sets := [][]uuid.UUID{}
for _, i := range ls {
......@@ -81,18 +81,18 @@ func MaxSubset(t int, superset [][]uuid.UUID) []uuid.UUID {
return subsets[max]
}
func Intersection(superset [][]uuid.UUID) []uuid.UUID {
func Intersection(superset [][]uuid.UUID) map[uuid.UUID]bool {
section := make(map[uuid.UUID]int, len(superset[0]))
for _, set := range superset {
for _, e := range set {
section[e]++
}
}
list := []uuid.UUID{}
set := make(map[uuid.UUID]bool)
for uuid, num := range section {
if num >= len(superset) {
list = append(list, uuid)
set[uuid] = true
}
}
return list
return set
}
......@@ -27,3 +27,26 @@ func TestIntersection(t *testing.T) {
if subset[elem[5]] { t.Fail() }
if subset[elem[6]] { t.Fail() }
}
func TestMaxSubset(t *testing.T) {
N := 7
elem := make([]uuid.UUID, N)
for i := 0; i < N; i++ {
elem[i] = uuid.New()
}
superset := [][]uuid.UUID{
[]uuid.UUID{elem[0], elem[1], elem[2], elem[3]},
[]uuid.UUID{elem[0], elem[1], elem[2], elem[4]},
[]uuid.UUID{elem[0], elem[1], elem[2], elem[5]},
[]uuid.UUID{elem[0], elem[1], elem[2], elem[6]},
[]uuid.UUID{elem[6]},
}
subset := MaxSubset(4, superset)
if !subset[elem[0]] { t.Fail() }
if !subset[elem[1]] { t.Fail() }
if !subset[elem[2]] { t.Fail() }
if subset[elem[3]] { t.Fail() }
if subset[elem[4]] { t.Fail() }
if subset[elem[5]] { t.Fail() }
if subset[elem[6]] { t.Fail() }
}
......@@ -3,6 +3,7 @@ module bsc-shamir
go 1.12
require (
github.com/gonum/stat v0.0.0-20181125101827-41a0da705a5b
github.com/google/uuid v1.1.1
github.com/jessevdk/go-flags v1.4.0
github.com/smartystreets/goconvey v1.6.4 // indirect
......
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jessevdk/go-flags v1.4.1-0.20181221193153-c0795c8afcf4 h1:xKkUL6QBojwguhKKetf1SocCAKqc6W7S/mGm9xEGllo=
github.com/jessevdk/go-flags v1.4.1-0.20181221193153-c0795c8afcf4/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/songgao/colorgo v0.0.0-20161028043718-1e1a5b5cef5c h1:hNhvGoZxQE5ePoOxtrkQcGuLgAwSYg6YXvV0uDkWLrc=
github.com/songgao/colorgo v0.0.0-20161028043718-1e1a5b5cef5c/go.mod h1:WLESiNTCbOJiawth75UhLjkk3F3hBR8VpTqFI2yYUfQ=
github.com/songgao/go.pipeline v0.0.0-20130524200353-edad9b8a9fc0 h1:eTRfdPvLMCzRs0fQGOkpD8iEW8i0KtEK4cLatj9Qo/8=
github.com/songgao/go.pipeline v0.0.0-20130524200353-edad9b8a9fc0/go.mod h1:yj4GyFI/4SQ5PrOYeqLr/PZivZs1bm8RDTwPNXHvQLs=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384 h1:TFlARGu6Czu1z7q93HTxcP1P+/ZFC/IKythI5RzrnRg=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
github.com/gonum/stat v0.0.0-20181125101827-41a0da705a5b h1:fbskpz/cPqWH8VqkQ7LJghFkl2KPAiIFUHrTJ2O3RGk=
github.com/gonum/stat v0.0.0-20181125101827-41a0da705a5b/go.mod h1:Z4GIJBJO3Wa4gD4vbwQxXXZ+WHmW6E9ixmNrwvs0iZs=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jessevdk/go-flags v1.4.1-0.20181221193153-c0795c8afcf4 h1:xKkUL6QBojwguhKKetf1SocCAKqc6W7S/mGm9xEGllo=
github.com/jessevdk/go-flags v1.4.1-0.20181221193153-c0795c8afcf4/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/songgao/colorgo v0.0.0-20161028043718-1e1a5b5cef5c h1:hNhvGoZxQE5ePoOxtrkQcGuLgAwSYg6YXvV0uDkWLrc=
github.com/songgao/colorgo v0.0.0-20161028043718-1e1a5b5cef5c/go.mod h1:WLESiNTCbOJiawth75UhLjkk3F3hBR8VpTqFI2yYUfQ=
github.com/songgao/go.pipeline v0.0.0-20130524200353-edad9b8a9fc0 h1:eTRfdPvLMCzRs0fQGOkpD8iEW8i0KtEK4cLatj9Qo/8=
github.com/songgao/go.pipeline v0.0.0-20130524200353-edad9b8a9fc0/go.mod h1:yj4GyFI/4SQ5PrOYeqLr/PZivZs1bm8RDTwPNXHvQLs=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384 h1:TFlARGu6Czu1z7q93HTxcP1P+/ZFC/IKythI5RzrnRg=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
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