Debian Codegraph @

search/main.go

raw symbols SCIP
1 package main
2
3 import (
4 "fmt"
5 "math"
6 "math/big"
7 "sort"
8 "sync"
9 )
10
11 func main() {
12 // build results
13 var results [][2]*big.Int
14 M := new(big.Int).Lsh(one, 256)
15 var mutex = &sync.Mutex{}
16 var waitGroup sync.WaitGroup
17 waitGroup.Add(255)
18 for j := uint(0); j < 255; j++ {
19 go func(j uint) {
20 defer waitGroup.Done()
21 M2 := new(big.Int).Set(M)
22 M2.Sub(M2, new(big.Int).Lsh(one, j))
23 var q, t *big.Int
24 q = M2
25 for {
26 q, t = nextSiec(q)
27 N := new(big.Int).Add(q, big.NewInt(1))
28 N.Sub(N, t)
29 N2 := new(big.Int).Add(q, big.NewInt(1))
30 N2.Add(N2, t)
31 if true || N.ProbablyPrime(25) || N2.ProbablyPrime(25) {
32 mutex.Lock()
33 results = append(results, [2]*big.Int{q, t})
34 mutex.Unlock()
35 return
36 }
37 }
38 }(j)
39 }
40 waitGroup.Wait()
41 // rank results
42 sort.Slice(results, func(i int, j int) bool {
43 n1 := results[i][0].BitLen()
44 c1 := popCount(results[i][0])
45 n2 := results[j][0].BitLen()
46 c2 := popCount(results[j][0])
47 return math.Abs(float64(n1-2*int(c1))) < math.Abs(float64(n2-2*int(c2)))
48 })
49 // print
50 for _, r := range results {
51 fmt.Printf("q = %x\ns = %d\nt = %x\n", r[0], popCount(r[0]), r[1])
52 }
53 }
54
55 func popCount(a *big.Int) (c uint) {
56 n := a.BitLen()
57 for i := 0; i <= n; i++ {
58 c += a.Bit(i)
59 }
60 return
61 }