func main() { for k, v := range []string{"id", "account_id", "action_type", "referrer_id", "contract_id", "payment_id", "amount", "balance_after"} { fmt.Println(k, v) } max := 1000000 s := time.Now().UnixNano() fmt.Println(17 / 2) // var m runtime.MemStats // // runtime.ReadMemStats(&m) // fmt.Println("Mem: ", m) s = time.Now().UnixNano() fmt.Println(len(prime.Primes(uint64(max)))) s = time.Now().UnixNano() - s fmt.Println(float64(s) / 1000000.0) // runtime.ReadMemStats(&m) // fmt.Println("Mem: ", m.Alloc) // s = time.Now().UnixNano() // fmt.Println(len(atkin.Atkin(max))) // s = time.Now().UnixNano() - s // fmt.Println(float64(s) / 1000000.0) // // runtime.ReadMemStats(&m) // fmt.Println("Mem: ", m.Alloc) }
func main() { flag.Parse() if *cpuprofile != "" { f, err := os.Create(*cpuprofile) if err != nil { log.Fatal(err) } pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() } t := time.Now().UnixNano() fmt.Println("number of primes (non-segmented-method):", len(prime.SieveOfEratosthenes(1000000000))) fmt.Println("number of primes (segmented-method):", len(prime.Primes(1000000000))) fmt.Println("seconds it took:", float64(time.Now().UnixNano()-t)/1000000000) if *memprofile != "" { f, err := os.Create(*memprofile) if err != nil { log.Fatal(err) } pprof.WriteHeapProfile(f) f.Close() return } }
func main() { s := time.Now().UnixNano() s = time.Now().UnixNano() fmt.Println(len(prime.Primes(1000000000))) s = time.Now().UnixNano() - s fmt.Println(float64(s) / 1000000.0) }
func main() { var digits int = 4 var max uint64 = 10 for i := 1; i < 8; i++ { max *= 10 } primes := prime.Primes(max) var dpf int = 0 for i := 1; uint64(i) < max; i++ { var factors int = 0 var currentNumber uint64 = uint64(i) for p := 0; p < len(primes); p++ { if currentNumber%primes[p] != 0 { continue } factors++ for currentNumber%primes[p] == 0 { currentNumber /= primes[p] } if currentNumber == 1 { if factors == digits { dpf++ } else { dpf = 0 } break } } if dpf == digits { fmt.Println("Solution Problem 47: ", i-digits+1) break } } }
package main import ( "fmt" "math" "strconv" "github.com/kavehmz/prime" ) var p []uint64 = prime.Primes(1000000) type PrimeDigit struct { count int min uint64 } func getMatchedDigit(v uint64, s string) uint64 { var matched uint64 = 10 var digit uint64 base := v for i := len(s) - 1; i >= 0; i-- { digit = v % 10 v = v / 10 if s[i] == '1' { if matched == 10 { matched = digit } else { if matched != digit { return 0 }