-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkey-gen-face-five.go
76 lines (63 loc) · 1.29 KB
/
key-gen-face-five.go
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
68
69
70
71
72
73
74
75
76
package main
import (
"fmt"
"time"
)
func main() {
// generate keys for faces 1, 2, 3,.., 9, T, J, Q, K, A
// keys are such that the sums of any 2 combinations of 5 faces (with max 4 repetition) are distincts
// (discarding all other card info)
nbKeys := 10
var solutions [][]int
keys := make([]int, nbKeys)
sumKeys := make([]int, 50000)
var valid bool
// bootstrapping
keys[0] = 0
keys[1] = 1
keys[2] = 5
k := 3
fmt.Printf("bootstrapping -> k=%d: keys=%v\n", k, keys)
t0 := time.Now()
nbKeys = 10
for k < nbKeys {
t := keys[k-1] + 1
valid = false
for !valid {
keys[k] = t
c := 0
for c1 := 0; c1 < k+1; c1++ {
for c2 := c1; c2 < k+1; c2++ {
for c3 := c2; c3 < k+1; c3++ {
for c4 := c3; c4 < k+1; c4++ {
for c5 := c4; c5 < k+1; c5++ {
if c1 != c5 {
sumKeys[c] = keys[c1] + keys[c2] + keys[c3] + keys[c4] + keys[c5]
c++
}
}
}
}
}
}
i := 0
valid = true
for (valid) && (i < c-1) {
j := i + 1
for (valid) && (j < c) {
if sumKeys[i] == sumKeys[j] {
valid = false
t++
}
j++
}
i++
}
}
t1 := time.Now()
dt := t1.Sub(t0)
fmt.Printf("k=%d: keys=%v - t=%.2f s\n", k, keys, dt.Seconds())
solutions = append(solutions, keys[:])
k++
}
}