WeixiangYan/CodeTransOcean huggingface dataset:
Task: Largest difference between adjacent primes




Go: package main

import (
    "fmt"
    "rcu"
)

func main() {
    limit := int(1e10 - 1)
    primes := rcu.Primes(limit)
    maxI := 0
    maxDiff := 0
    nextStop := 10
    fmt.Println("The largest differences between adjacent primes under the following limits is:")
    for i := 1; i < len(primes); i++ {
        diff := primes[i] - primes[i-1]
        if diff > maxDiff {
            maxDiff = diff
            maxI = i
        }
        if i == len(primes)-1 || primes[i+1] > nextStop {
            c1 := rcu.Commatize(nextStop)
            c2 := rcu.Commatize(primes[maxI])
            c3 := rcu.Commatize(primes[maxI-1])
            c4 := rcu.Commatize(maxDiff)
            fmt.Printf("Under %s: %s - %s = %s\n", c1, c2, c3, c4)
            nextStop *= 10
        }
    }
}
Task: Minimum primes




Go: package main

import (
    "fmt"
    "rcu"
)

func main() {
    numbers1 := [5]int{5, 45, 23, 21, 67}
    numbers2 := [5]int{43, 22, 78, 46, 38}
    numbers3 := [5]int{9, 98, 12, 54, 53}
    primes := [5]int{}
    for n := 0; n < 5; n++ {
        max := rcu.Max(rcu.Max(numbers1[n], numbers2[n]), numbers3[n])
        if max % 2 == 0 {
            max++
        }
        for !rcu.IsPrime(max) {
            max += 2
        }
        primes[n] = max
    }
    fmt.Println(primes)
}
Task: Linux CPU utilization




Go: package main

import (
    "bufio"
    "fmt"
    "log"
    "os"
    "strconv"
    "strings"
    "time"
)

func main() {
    fmt.Println("CPU usage % at 1 second intervals:\n")
    var prevIdleTime, prevTotalTime uint64
    for i := 0; i < 10; i++ {
        file, err := os.Open("/proc/stat")
        if err != nil {
            log.Fatal(err)
        }
        scanner := bufio.NewScanner(file)
        scanner.Scan()
        firstLine := scanner.Text()[5:] 
        file.Close()
        if err := scanner.Err(); err != nil {
            log.Fatal(err)
        }
        split := strings.Fields(firstLine)
        idleTime, _ := strconv.ParseUint(split[3], 10, 64)
        totalTime := uint64(0)
        for _, s := range split {
            u, _ := strconv.ParseUint(s, 10, 64)
            totalTime += u
        }
        if i > 0 {
            deltaIdleTime := idleTime - prevIdleTime
            deltaTotalTime := totalTime - prevTotalTime
            cpuUsage := (1.0 - float64(deltaIdleTime)/float64(deltaTotalTime)) * 100.0
            fmt.Printf("%d : %6.3f\n", i, cpuUsage)
        }
        prevIdleTime = idleTime
        prevTotalTime = totalTime
        time.Sleep(time.Second)
    }
}
Task: Useless instructions




Go: package main

import (
    "fmt"
)

type any = interface{}

func uselessFunc(uselessParam any) { 
    if true {
        
    } else {
        fmt.Println("Never called")
    }

    for range []any{} {
        fmt.Println("Never called")
    }

    for false {
        fmt.Println("Never called")
    }

    fmt.Print("") 

    return 
}

type NotCompletelyUseless struct {
    
}

func main() {
    uselessFunc(0)
    set := make(map[int]NotCompletelyUseless)
    set[0] = NotCompletelyUseless{}
    set[0] = NotCompletelyUseless{} 
    fmt.Println(set)
}
Task: Ulam numbers




Go: package main

import "fmt"

func ulam(n int) int {
    ulams := []int{1, 2}
    set := map[int]bool{1: true, 2: true}
    i := 3
    for {
        count := 0
        for j := 0; j < len(ulams); j++ {
            _, ok := set[i-ulams[j]]
            if ok && ulams[j] != (i-ulams[j]) {
                count++
                if count > 2 {
                    break
                }
            }
        }
        if count == 2 {
            ulams = append(ulams, i)
            set[i] = true
            if len(ulams) == n {
                break
            }
        }
        i++
    }
    return ulams[n-1]
}

func main() {
    for n := 10; n <= 10000; n *= 10 {
        fmt.Println("The", n, "\bth Ulam number is", ulam(n))
    }
}
Task: Ramsey's theorem




Go: package main

import "fmt"

var (
    a   [17][17]int
    idx [4]int
)

func findGroup(ctype, min, max, depth int) bool {
    if depth == 4 {
        cs := ""
        if ctype == 0 {
            cs = "un"
        }
        fmt.Printf("Totally %sconnected group:", cs)
        for i := 0; i < 4; i++ {
            fmt.Printf(" %d", idx[i])
        }
        fmt.Println()
        return true
    }

    for i := min; i < max; i++ {
        n := 0
        for ; n < depth; n++ {
            if a[idx[n]][i] != ctype {
                break
            }
        }

        if n == depth {
            idx[n] = i
            if findGroup(ctype, 1, max, depth+1) {
                return true
            }
        }
    }
    return false
}

func main() {
    const mark = "01-"

    for i := 0; i < 17; i++ {
        a[i][i] = 2
    }

    for k := 1; k <= 8; k <<= 1 {
        for i := 0; i < 17; i++ {
            j := (i + k) % 17
            a[i][j], a[j][i] = 1, 1
        }
    }

    for i := 0; i < 17; i++ {
        for j := 0; j < 17; j++ {
            fmt.Printf("%c ", mark[a[i][j]])
        }
        fmt.Println()
    }

    
    

    
    for i := 0; i < 17; i++ {
        idx[0] = i
        if findGroup(1, i+1, 17, 1) || findGroup(0, i+1, 17, 1) {
            fmt.Println("No good.")
            return
        }
    }
    fmt.Println("All good.")
}
Task: Smallest power of 6 whose decimal expansion contains n




Go: package main

import (
    "fmt"
    "math/big"
    "strconv"
    "strings"
)


func commatize(s string) string {
    neg := false
    if strings.HasPrefix(s, "-") {
        s = s[1:]
        neg = true
    }
    le := len(s)
    for i := le - 3; i >= 1; i -= 3 {
        s = s[0:i] + "," + s[i:]
    }
    if !neg {
        return s
    }
    return "-" + s
}

func main() {
    fmt.Println(" n  smallest power of 6 which contains n")
    six := big.NewInt(6)
    for n := 0; n <= 21; n++ {
        ns := strconv.Itoa(n)
        i := int64(0)
        for {
            bi := big.NewInt(i)
            pow6 := bi.Exp(six, bi, nil).String()
            if strings.Contains(pow6, ns) {
                fmt.Printf("%2d  6^%-2d = %s\n", n, i, commatize(pow6))
                break
            }
            i++
        }
    }
}
Task: Type detection




Go: package main

import "fmt"

type any = interface{}

func showType(a any) {
    switch a.(type) {
    case rune:
        fmt.Printf("The type of '%c' is %T\n", a, a)
    default:
        fmt.Printf("The type of '%v' is %T\n", a, a)
    }
}

func main() {
    values := []any{5, 7.5, 2 + 3i, 'd', true, "Rosetta"}
    for _, value := range values {
        showType(value)
    }
}
Task: Steady squares




Go: package main

import (
    "fmt"
    "rcu"
    "strconv"
    "strings"
)

func contains(list []int, s int) bool {
    for _, e := range list {
        if e == s {
            return true
        }
    }
    return false
}

func main() {
    fmt.Println("Steady squares under 10,000:")
    finalDigits := []int{1, 5, 6}
    for i := 1; i < 10000; i++ {
        if !contains(finalDigits, i%10) {
            continue
        }
        sq := i * i
        sqs := strconv.Itoa(sq)
        is := strconv.Itoa(i)
        if strings.HasSuffix(sqs, is) {
            fmt.Printf("%5s -> %10s\n", rcu.Commatize(i), rcu.Commatize(sq))
        }
    }
}
Task: Primes which contain only one odd digit




Go: package main

import (
    "fmt"
    "rcu"
)

func allButOneEven(prime int) bool {
    digits := rcu.Digits(prime, 10)
    digits = digits[:len(digits)-1]
    allEven := true
    for _, d := range digits {
        if d&1 == 1 {
            allEven = false
            break
        }
    }
    return allEven
}

func main() {
    const (
        LIMIT      = 999
        LIMIT2     = 9999999999
        MAX_DIGITS = 3
    )
    primes := rcu.Primes(LIMIT)
    var results []int
    for _, prime := range primes[1:] {
        if allButOneEven(prime) {
            results = append(results, prime)
        }
    }
    fmt.Println("Primes under", rcu.Commatize(LIMIT+1), "which contain only one odd digit:")
    for i, p := range results {
        fmt.Printf("%*s ", MAX_DIGITS, rcu.Commatize(p))
        if (i+1)%9 == 0 {
            fmt.Println()
        }
    }
    fmt.Println("\nFound", len(results), "such primes.\n")

    primes = rcu.Primes(LIMIT2)
    count := 0
    pow := 10
    for _, prime := range primes[1:] {
        if allButOneEven(prime) {
            count++
        }
        if prime > pow {
            fmt.Printf("There are %7s such primes under %s\n", rcu.Commatize(count), rcu.Commatize(pow))
            pow *= 10
        }
    }
    fmt.Printf("There are %7s such primes under %s\n", rcu.Commatize(count), rcu.Commatize(pow))
}
Task: Safe primes and unsafe primes




Go: package main

import "fmt"

func sieve(limit uint64) []bool {
    limit++
    
    c := make([]bool, limit) 
    c[0] = true
    c[1] = true
    
    for i := uint64(4); i < limit; i += 2 {
        c[i] = true
    }
    p := uint64(3) 
    for {
        p2 := p * p
        if p2 >= limit {
            break
        }
        for i := p2; i < limit; i += 2 * p {
            c[i] = true
        }
        for {
            p += 2
            if !c[p] {
                break
            }
        }
    }
    return c
}

func commatize(n int) string {
    s := fmt.Sprintf("%d", n)
    if n < 0 {
        s = s[1:]
    }
    le := len(s)
    for i := le - 3; i >= 1; i -= 3 {
        s = s[0:i] + "," + s[i:]
    }
    if n >= 0 {
        return s
    }
    return "-" + s
}

func main() {
    
    sieved := sieve(1e7)
    var safe = make([]int, 35)
    count := 0
    for i := 3; count < 35; i += 2 {
        if !sieved[i] && !sieved[(i-1)/2] {
            safe[count] = i
            count++
        }
    }
    fmt.Println("The first 35 safe primes are:\n", safe, "\n")

    count = 0
    for i := 3; i < 1e6; i += 2 {
        if !sieved[i] && !sieved[(i-1)/2] {
            count++
        }
    }
    fmt.Println("The number of safe primes below 1,000,000 is", commatize(count), "\n")

    for i := 1000001; i < 1e7; i += 2 {
        if !sieved[i] && !sieved[(i-1)/2] {
            count++
        }
    }
    fmt.Println("The number of safe primes below 10,000,000 is", commatize(count), "\n")

    unsafe := make([]int, 40)
    unsafe[0] = 2 
    count = 1
    for i := 3; count < 40; i += 2 {
        if !sieved[i] && sieved[(i-1)/2] {
            unsafe[count] = i
            count++
        }
    }
    fmt.Println("The first 40 unsafe primes are:\n", unsafe, "\n")

    count = 1
    for i := 3; i < 1e6; i += 2 {
        if !sieved[i] && sieved[(i-1)/2] {
            count++
        }
    }
    fmt.Println("The number of unsafe primes below 1,000,000 is", commatize(count), "\n")

    for i := 1000001; i < 1e7; i += 2 {
        if !sieved[i] && sieved[(i-1)/2] {
            count++
        }
    }
    fmt.Println("The number of unsafe primes below 10,000,000 is", commatize(count), "\n")
}
Task: Hash join




Go: package main

import "fmt"

func main() {
    tableA := []struct {
        value int
        key   string
    }{
        {27, "Jonah"}, {18, "Alan"}, {28, "Glory"}, {18, "Popeye"},
        {28, "Alan"},
    }
    tableB := []struct {
        key   string
        value string
    }{
        {"Jonah", "Whales"}, {"Jonah", "Spiders"},
        {"Alan", "Ghosts"}, {"Alan", "Zombies"}, {"Glory", "Buffy"},
    }
    
    h := map[string][]int{}
    for i, r := range tableA {
        h[r.key] = append(h[r.key], i)
    }
    
    for _, x := range tableB {
        for _, a := range h[x.key] {
            fmt.Println(tableA[a], x)
        }
    }
}
Task: Substring primes




Go: package main

import (
    "fmt"
    "rcu"
)

func main() {
    primes := rcu.Primes(499)
    var sprimes []int
    for _, p := range primes {
        digits := rcu.Digits(p, 10)
        var b1 = true
        for _, d := range digits {
            if !rcu.IsPrime(d) {
                b1 = false
                break
            }
        }
        if b1 {
            if len(digits) < 3 {
                sprimes = append(sprimes, p)
            } else {
                b2 := rcu.IsPrime(digits[0]*10 + digits[1])
                b3 := rcu.IsPrime(digits[1]*10 + digits[2])
                if b2 && b3 {
                    sprimes = append(sprimes, p)
                }
            }
        }
    }
    fmt.Println("Found", len(sprimes), "primes < 500 where all substrings are also primes, namely:")
    fmt.Println(sprimes)
}
Task: Numbers whose count of divisors is prime




Go: package main

import (
    "fmt"
    "rcu"
)

func countDivisors(n int) int {
    count := 0
    i := 1
    k := 1
    if n%2 == 1 {
        k = 2
    }
    for ; i*i <= n; i += k {
        if n%i == 0 {
            count++
            j := n / i
            if j != i {
                count++
            }
        }
    }
    return count
}

func main() {
    const limit = 1e5
    var results []int
    for i := 2; i * i < limit; i++ {
        n := countDivisors(i * i)
        if n > 2 && rcu.IsPrime(n) {
            results = append(results, i * i)
        }
    }
    climit := rcu.Commatize(limit)
    fmt.Printf("Positive integers under %7s whose number of divisors is an odd prime:\n", climit)
    under1000 := 0
    for i, n := range results {
        fmt.Printf("%7s", rcu.Commatize(n))
        if (i+1)%10 == 0 {
            fmt.Println()
        }
        if n < 1000 {
            under1000++
        }
    }
    fmt.Printf("\n\nFound %d such integers (%d under 1,000).\n", len(results), under1000)
}
Task: Giuga numbers




Go: package main

import "fmt"

var factors []int
var inc = []int{4, 2, 4, 2, 4, 6, 2, 6}



func primeFactors(n int) {
    factors = factors[:0]
    factors = append(factors, 2)
    last := 2
    n /= 2
    for n%3 == 0 {
        if last == 3 {
            factors = factors[:0]
            return
        }
        last = 3
        factors = append(factors, 3)
        n /= 3
    }
    for n%5 == 0 {
        if last == 5 {
            factors = factors[:0]
            return
        }
        last = 5
        factors = append(factors, 5)
        n /= 5
    }
    for k, i := 7, 0; k*k <= n; {
        if n%k == 0 {
            if last == k {
                factors = factors[:0]
                return
            }
            last = k
            factors = append(factors, k)
            n /= k
        } else {
            k += inc[i]
            i = (i + 1) % 8
        }
    }
    if n > 1 {
        factors = append(factors, n)
    }
}

func main() {
    const limit = 5
    var giuga []int
    
    for n := 6; len(giuga) < limit; n += 4 {
        primeFactors(n)
        
        if len(factors) > 2 {
            isGiuga := true
            for _, f := range factors {
                if (n/f-1)%f != 0 {
                    isGiuga = false
                    break
                }
            }
            if isGiuga {
                giuga = append(giuga, n)
            }
        }
    }
    fmt.Println("The first", limit, "Giuga numbers are:")
    fmt.Println(giuga)
}
Task: Permutations with repetitions




Go: package main

import "fmt"

var (
    n      = 3
    values = []string{"A", "B", "C", "D"}
    k      = len(values)
    decide = func(p []string) bool {
        return p[0] == "B" && p[1] == "C"
    }
)

func main() {
    pn := make([]int, n)
    p := make([]string, n)
    for {
        
        for i, x := range pn {
            p[i] = values[x]
        }
        
        fmt.Println(p)
        
        if decide(p) {
            return 
        }
        
        for i := 0; ; {
            pn[i]++
            if pn[i] < k {
                break
            }
            pn[i] = 0
            i++
            if i == n {
                return 
            }
        }
    }
}
Task: Idiomatically determine all the characters that can be used for symbols




Go: package main

import (
	"fmt"
	"go/ast"
	"go/parser"
	"strings"
	"unicode"
)

func isValidIdentifier(identifier string) bool {
	node, err := parser.ParseExpr(identifier)
	if err != nil {
		return false
	}
	ident, ok := node.(*ast.Ident)
	return ok && ident.Name == identifier
}

type runeRanges struct {
	ranges   []string
	hasStart bool
	start    rune
	end      rune
}

func (r *runeRanges) add(cp rune) {
	if !r.hasStart {
		r.hasStart = true
		r.start = cp
		r.end = cp
		return
	}

	if cp == r.end+1 {
		r.end = cp
		return
	}

	r.writeTo(&r.ranges)

	r.start = cp
	r.end = cp
}

func (r *runeRanges) writeTo(ranges *[]string) {
	if r.hasStart {
		if r.start == r.end {
			*ranges = append(*ranges, fmt.Sprintf("%U", r.end))
		} else {
			*ranges = append(*ranges, fmt.Sprintf("%U-%U", r.start, r.end))
		}
	}
}

func (r *runeRanges) String() string {
	ranges := r.ranges
	r.writeTo(&ranges)
	return strings.Join(ranges, ", ")
}

func main() {
	var validFirst runeRanges
	var validFollow runeRanges
	var validOnlyFollow runeRanges

	for r := rune(0); r <= unicode.MaxRune; r++ {
		first := isValidIdentifier(string([]rune{r}))
		follow := isValidIdentifier(string([]rune{'_', r}))
		if first {
			validFirst.add(r)
		}
		if follow {
			validFollow.add(r)
		}
		if follow && !first {
			validOnlyFollow.add(r)
		}
	}

	_, _ = fmt.Println("Valid first:", validFirst.String())
	_, _ = fmt.Println("Valid follow:", validFollow.String())
	_, _ = fmt.Println("Only follow:", validOnlyFollow.String())
}
Task: Selective file copy




Go: package main

import (
    "encoding/json"
    "log"
    "os"
    "bytes"
    "errors"
    "strings"
)


type s1 struct {
    A string
    B string
    C int
    D string
}


type s2 struct {
    A string
    C intString 
    X string
}

type intString string

func (i *intString) UnmarshalJSON(b []byte) error {
    if len(b) == 0 || bytes.IndexByte([]byte("0123456789-"), b[0]) < 0 {
        return errors.New("Unmarshal intString expected JSON number")
    }
    *i = intString(b)
    return nil
}


func NewS2() *s2 {
    return &s2{X: "XXXXX"}
}

func main() {
    
    o1, err := os.Create("o1.json")
    if err != nil {
        log.Fatal(err)
    }
    e := json.NewEncoder(o1)
    for i := 1; i <= 5; i++ {
        err := e.Encode(s1{
            strings.Repeat("A", i),
            strings.Repeat("B", i),
            i,
            strings.Repeat("D", i),
        })
        if err != nil {
            log.Fatal(err)
        }
    }
    o1.Close()

    
    in, err := os.Open("o1.json")
    if err != nil {
        log.Fatal(err)
    }
    out, err := os.Create("out.json")
    if err != nil {
        log.Fatal(err)
    }
    
    d := json.NewDecoder(in)
    e = json.NewEncoder(out)
    for d.More() {
        
        
        
        
        s := NewS2()
        if err = d.Decode(s); err != nil {
            log.Fatal(err)
        }
        if err = e.Encode(s); err != nil {
            log.Fatal(err)
        }
    }
}
Task: Audio alarm




Go: package main

import (
    "bufio"
    "fmt"
    "log"
    "os"
    "os/exec"
    "strconv"
    "time"
)

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    number := 0
    for number < 1 {
        fmt.Print("Enter number of seconds delay > 0 : ")
        scanner.Scan()
        input := scanner.Text()
        if err := scanner.Err(); err != nil {
            log.Fatal(err)
        }
        number, _ = strconv.Atoi(input)
    }

    filename := ""
    for filename == "" {
        fmt.Print("Enter name of .mp3 file to play (without extension) : ")
        scanner.Scan()
        filename = scanner.Text()
        if err := scanner.Err(); err != nil {
            log.Fatal(err)
        }
    }

    cls := "\033[2J\033[0;0H" 
    fmt.Printf("%sAlarm will sound in %d seconds...", cls, number)
    time.Sleep(time.Duration(number) * time.Second)
    fmt.Printf(cls)
    cmd := exec.Command("play", filename+".mp3")
    if err := cmd.Run(); err != nil {
        log.Fatal(err)
    }
}
Task: Quadrat special primes




Go: package main

import (
    "fmt"
    "math"
)

func sieve(limit int) []bool {
    limit++
    
    c := make([]bool, limit) 
    c[0] = true
    c[1] = true
    
    p := 3 
    for {
        p2 := p * p
        if p2 >= limit {
            break
        }
        for i := p2; i < limit; i += 2 * p {
            c[i] = true
        }
        for {
            p += 2
            if !c[p] {
                break
            }
        }
    }
    return c
}

func isSquare(n int) bool {
    s := int(math.Sqrt(float64(n)))
    return s*s == n
}

func commas(n int) string {
    s := fmt.Sprintf("%d", n)
    if n < 0 {
        s = s[1:]
    }
    le := len(s)
    for i := le - 3; i >= 1; i -= 3 {
        s = s[0:i] + "," + s[i:]
    }
    if n >= 0 {
        return s
    }
    return "-" + s
}

func main() {
    c := sieve(15999)
    fmt.Println("Quadrat special primes under 16,000:")
    fmt.Println(" Prime1  Prime2    Gap  Sqrt")
    lastQuadSpecial := 3
    gap := 1
    count := 1
    fmt.Printf("%7d %7d %6d %4d\n", 2, 3, 1, 1)
    for i := 5; i < 16000; i += 2 {
        if c[i] {
            continue
        }
        gap = i - lastQuadSpecial
        if isSquare(gap) {
            sqrt := int(math.Sqrt(float64(gap)))
            fmt.Printf("%7s %7s %6s %4d\n", commas(lastQuadSpecial), commas(i), commas(gap), sqrt)
            lastQuadSpecial = i
            count++
        }
    }
    fmt.Println("\n", count+1, "such primes found.")
}
Task: Euclid-Mullin sequence




Go: package main

import (
    "fmt"
    big "github.com/ncw/gmp"
    "log"
)

var (
    zero  = big.NewInt(0)
    one   = big.NewInt(1)
    two   = big.NewInt(2)
    three = big.NewInt(3)
    four  = big.NewInt(4)
    five  = big.NewInt(5)
    six   = big.NewInt(6)
    ten   = big.NewInt(10)
    max   = big.NewInt(100000)
)

func pollardRho(n, c *big.Int) *big.Int {
    g := func(x, y *big.Int) *big.Int {
        x2 := new(big.Int)
        x2.Mul(x, x)
        x2.Add(x2, c)
        return x2.Mod(x2, y)
    }
    x, y, z := big.NewInt(2), big.NewInt(2), big.NewInt(1)
    d := new(big.Int)
    count := 0
    for {
        x = g(x, n)
        y = g(g(y, n), n)
        d.Sub(x, y)
        d.Abs(d)
        d.Mod(d, n)
        z.Mul(z, d)
        count++
        if count == 100 {
            d.GCD(nil, nil, z, n)
            if d.Cmp(one) != 0 {
                break
            }
            z.Set(one)
            count = 0
        }
    }
    if d.Cmp(n) == 0 {
        return zero
    }
    return d
}

func smallestPrimeFactorWheel(n *big.Int) *big.Int {
    if n.ProbablyPrime(15) {
        return n
    }
    z := new(big.Int)
    if z.Rem(n, two).Cmp(zero) == 0 {
        return two
    }
    if z.Rem(n, three).Cmp(zero) == 0 {
        return three
    }
    if z.Rem(n, five).Cmp(zero) == 0 {
        return five
    }
    k := big.NewInt(7)
    i := 0
    inc := []*big.Int{four, two, four, two, four, six, two, six}
    for z.Mul(k, k).Cmp(n) <= 0 {
        if z.Rem(n, k).Cmp(zero) == 0 {
            return k
        }
        k.Add(k, inc[i])
        if k.Cmp(max) > 0 {
            break
        }
        i = (i + 1) % 8
    }
    return nil
}

func smallestPrimeFactor(n *big.Int) *big.Int {
    s := smallestPrimeFactorWheel(n)
    if s != nil {
        return s
    }
    c := big.NewInt(1)
    s = new(big.Int).Set(n)
    for n.Cmp(max) > 0 {
        d := pollardRho(n, c)
        if d.Cmp(zero) == 0 {
            if c.Cmp(ten) == 0 {
                log.Fatal("Pollard Rho doesn't appear to be working.")
            }
            c.Add(c, one)
        } else {
            
            if d.Cmp(s) < 0 {
                s.Set(d)
            }
            n.Quo(n, d)
            if n.ProbablyPrime(5) {
                if n.Cmp(s) < 0 {
                    return n
                }
                return s
            }
        }
    }
    return s
}

func main() {
    k := 19
    fmt.Println("First", k, "terms of the Euclid–Mullin sequence:")
    fmt.Println(2)
    prod := big.NewInt(2)
    z := new(big.Int)
    count := 1
    for count < k {
        z.Add(prod, one)
        t := smallestPrimeFactor(z)
        fmt.Println(t)
        prod.Mul(prod, t)
        count++
    }
}