WeixiangYan/CodeTransOcean huggingface dataset:
Task: Square form factorization




Go: package main

import (
    "fmt"
    "math"
)

func isqrt(x uint64) uint64 {
    x0 := x >> 1
    x1 := (x0 + x/x0) >> 1
    for x1 < x0 {
        x0 = x1
        x1 = (x0 + x/x0) >> 1
    }
    return x0
}

func gcd(x, y uint64) uint64 {
    for y != 0 {
        x, y = y, x%y
    }
    return x
}

var multiplier = []uint64{
    1, 3, 5, 7, 11, 3 * 5, 3 * 7, 3 * 11, 5 * 7, 5 * 11, 7 * 11, 3 * 5 * 7, 3 * 5 * 11, 3 * 7 * 11, 5 * 7 * 11, 3 * 5 * 7 * 11,
}

func squfof(N uint64) uint64 {
    s := uint64(math.Sqrt(float64(N)) + 0.5)
    if s*s == N {
        return s
    }
    for k := 0; k < len(multiplier) && N <= math.MaxUint64/multiplier[k]; k++ {
        D := multiplier[k] * N
        P := isqrt(D)
        Pprev := P
        Po := Pprev
        Qprev := uint64(1)
        Q := D - Po*Po
        L := uint32(isqrt(8 * s))
        B := 3 * L
        i := uint32(2)
        var b, q, r uint64
        for ; i < B; i++ {
            b = uint64((Po + P) / Q)
            P = b*Q - P
            q = Q
            Q = Qprev + b*(Pprev-P)
            r = uint64(math.Sqrt(float64(Q)) + 0.5)
            if (i&1) == 0 && r*r == Q {
                break
            }
            Qprev = q
            Pprev = P
        }
        if i >= B {
            continue
        }
        b = uint64((Po - P) / r)
        P = b*r + P
        Pprev = P
        Qprev = r
        Q = (D - Pprev*Pprev) / Qprev
        i = 0
        for {
            b = uint64((Po + P) / Q)
            Pprev = P
            P = b*Q - P
            q = Q
            Q = Qprev + b*(Pprev-P)
            Qprev = q
            i++
            if P == Pprev {
                break
            }
        }
        r = gcd(N, Qprev)
        if r != 1 && r != N {
            return r
        }
    }
    return 0
}

func main() {
    examples := []uint64{
        2501,
        12851,
        13289,
        75301,
        120787,
        967009,
        997417,
        7091569,
        13290059,
        42854447,
        223553581,
        2027651281,
        11111111111,
        100895598169,
        1002742628021,
        60012462237239,
        287129523414791,
        9007199254740931,
        11111111111111111,
        314159265358979323,
        384307168202281507,
        419244183493398773,
        658812288346769681,
        922337203685477563,
        1000000000000000127,
        1152921505680588799,
        1537228672809128917,
        4611686018427387877,
    }
    fmt.Println("Integer              Factor     Quotient")
    fmt.Println("------------------------------------------")
    for _, N := range examples {
        fact := squfof(N)
        quot := "fail"
        if fact > 0 {
            quot = fmt.Sprintf("%d", N/fact)
        }
        fmt.Printf("%-20d %-10d %s\n", N, fact, quot)
    }
}
Task: Sunflower fractal




Go: package main

import (
    "github.com/fogleman/gg"
    "math"
)

func main() {
    dc := gg.NewContext(400, 400)
    dc.SetRGB(1, 1, 1)
    dc.Clear()
    dc.SetRGB(0, 0, 1)
    c := (math.Sqrt(5) + 1) / 2
    numberOfSeeds := 3000
    for i := 0; i <= numberOfSeeds; i++ {
        fi := float64(i)
        fn := float64(numberOfSeeds)
        r := math.Pow(fi, c) / fn
        angle := 2 * math.Pi * c * fi
        x := r*math.Sin(angle) + 200
        y := r*math.Cos(angle) + 200
        fi /= fn / 5
        dc.DrawCircle(x, y, fi)
    }
    dc.SetLineWidth(1)
    dc.Stroke()
    dc.SavePNG("sunflower_fractal.png")
}
Task: O'Halloran numbers




Go: package main

import "fmt"

func main() {
    found := make([]bool, 1000) 
    for l := 1; l < 498; l++ {
        for w := 1; w <= l; w++ {
            lw := l * w
            if lw >= 498 {
                break
            }
            for h := 1; h <= w; h++ {
                sa := (lw + w*h + h*l) * 2
                if sa < 1000 {
                    found[sa] = true
                }
            }
        }
    }
    fmt.Printf("All known O'Halloran numbers:\n[")
    for i := 6; i < 1000; i += 2 {
        if !found[i] {
            fmt.Printf("%d, ", i)
        }
    }
    fmt.Printf("\b\b]\n")
}
Task: Calmo numbers




Go: package main

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

func main() {
    const limit = 1000
    fmt.Println("Calmo numbers under 1,000:\n")
    fmt.Println("Number  Eligible divisors      Partial sums")
    fmt.Println("-------------------------------------------")
    for i := 2; i < limit; i++ {
        ed := rcu.ProperDivisors(i)[1:]
        l := len(ed)
        if l == 0 || l%3 != 0 {
            continue
        }
        isCalmo := true
        var ps []int
        for j := 0; j < l; j += 3 {
            sum := ed[j] + ed[j+1] + ed[j+2]
            if !rcu.IsPrime(sum) {
                isCalmo = false
                break
            }
            ps = append(ps, sum)
        }
        if isCalmo {
            eds := make([]string, len(ed))
            for k, e := range ed {
                eds[k] = strconv.Itoa(e)
            }
            seds := "[" + strings.Join(eds, " ") + "]"
            fmt.Printf("%3d     %-21s  %v\n", i, seds, ps)
        }
    }
}
Task: Practical numbers




Go: package main

import (
    "fmt"
    "rcu"
)

func powerset(set []int) [][]int {
    if len(set) == 0 {
        return [][]int{{}}
    }
    head := set[0]
    tail := set[1:]
    p1 := powerset(tail)
    var p2 [][]int
    for _, s := range powerset(tail) {
        h := []int{head}
        h = append(h, s...)
        p2 = append(p2, h)
    }
    return append(p1, p2...)
}

func isPractical(n int) bool {
    if n == 1 {
        return true
    }
    divs := rcu.ProperDivisors(n)
    subsets := powerset(divs)
    found := make([]bool, n) 
    count := 0
    for _, subset := range subsets {
        sum := rcu.SumInts(subset)
        if sum > 0 && sum < n && !found[sum] {
            found[sum] = true
            count++
            if count == n-1 {
                return true
            }
        }
    }
    return false
}

func main() {
    fmt.Println("In the range 1..333, there are:")
    var practical []int
    for i := 1; i <= 333; i++ {
        if isPractical(i) {
            practical = append(practical, i)
        }
    }
    fmt.Println(" ", len(practical), "practical numbers")
    fmt.Println("  The first ten are", practical[0:10])
    fmt.Println("  The final ten are", practical[len(practical)-10:])
    fmt.Println("\n666 is practical:", isPractical(666))
}
Task: Inner classes




Go: package main

import "fmt"

type Outer struct {
    field int
    Inner struct {
        field int
    }
}

func (o *Outer) outerMethod() {
    fmt.Println("Outer's field has a value of", o.field)
}

func (o *Outer) innerMethod() {
    fmt.Println("Inner's field has a value of", o.Inner.field)
}

func main() {
    o := &Outer{field: 43}
    o.Inner.field = 42
    o.innerMethod()
    o.outerMethod()
    
    p := &Outer{
        field: 45,
        Inner: struct {
            field int
        }{
            field: 44,
        },
    }
    p.innerMethod()
    p.outerMethod()
}
Task: Even numbers which cannot be expressed as the sum of two twin primes




Go: package main

import (
    "fmt"
    "rcu"
)

const limit = 100000 

func nonTwinSums(twins []int) []int {
    sieve := make([]bool, limit+1)
    for i := 0; i < len(twins); i++ {
        for j := i; j < len(twins); j++ {
            sum := twins[i] + twins[j]
            if sum > limit {
                break
            }
            sieve[sum] = true
        }
    }
    var res []int
    for i := 2; i < limit; i += 2 {
        if !sieve[i] {
            res = append(res, i)
        }
    }
    return res
}

func main() {
    primes := rcu.Primes(limit)[2:] 
    twins := []int{3}
    for i := 0; i < len(primes)-1; i++ {
        if primes[i+1]-primes[i] == 2 {
            if twins[len(twins)-1] != primes[i] {
                twins = append(twins, primes[i])
            }
            twins = append(twins, primes[i+1])
        }
    }
    fmt.Println("Non twin prime sums:")
    ntps := nonTwinSums(twins)
    rcu.PrintTable(ntps, 10, 4, false)
    fmt.Println("Found", len(ntps))

    fmt.Println("\nNon twin prime sums (including 1):")
    twins = append([]int{1}, twins...)
    ntps = nonTwinSums(twins)
    rcu.PrintTable(ntps, 10, 4, false)
    fmt.Println("Found", len(ntps))
}
Task: Penrose tiling




Go: package main

import (
    "github.com/fogleman/gg"
    "math"
)

type tiletype int

const (
    kite tiletype = iota
    dart
)

type tile struct {
    tt          tiletype
    x, y        float64
    angle, size float64
}

var gr = (1 + math.Sqrt(5)) / 2 

const theta = math.Pi / 5 

func setupPrototiles(w, h int) []tile {
    var proto []tile
    
    for a := math.Pi/2 + theta; a < 3*math.Pi; a += 2 * theta {
        ww := float64(w / 2)
        hh := float64(h / 2)
        proto = append(proto, tile{kite, ww, hh, a, float64(w) / 2.5})
    }
    return proto
}

func distinctTiles(tls []tile) []tile {
    tileset := make(map[tile]bool)
    for _, tl := range tls {
        tileset[tl] = true
    }
    distinct := make([]tile, len(tileset))
    for tl, _ := range tileset {
        distinct = append(distinct, tl)
    }
    return distinct
}

func deflateTiles(tls []tile, gen int) []tile {
    if gen <= 0 {
        return tls
    }
    var next []tile
    for _, tl := range tls {
        x, y, a, size := tl.x, tl.y, tl.angle, tl.size/gr
        var nx, ny float64
        if tl.tt == dart {
            next = append(next, tile{kite, x, y, a + 5*theta, size})
            for i, sign := 0, 1.0; i < 2; i, sign = i+1, -sign {
                nx = x + math.Cos(a-4*theta*sign)*gr*tl.size
                ny = y - math.Sin(a-4*theta*sign)*gr*tl.size
                next = append(next, tile{dart, nx, ny, a - 4*theta*sign, size})
            }
        } else {
            for i, sign := 0, 1.0; i < 2; i, sign = i+1, -sign {
                next = append(next, tile{dart, x, y, a - 4*theta*sign, size})
                nx = x + math.Cos(a-theta*sign)*gr*tl.size
                ny = y - math.Sin(a-theta*sign)*gr*tl.size
                next = append(next, tile{kite, nx, ny, a + 3*theta*sign, size})
            }
        }
    }
    
    tls = distinctTiles(next)
    return deflateTiles(tls, gen-1)
}

func drawTiles(dc *gg.Context, tls []tile) {
    dist := [2][3]float64{{gr, gr, gr}, {-gr, -1, -gr}}
    for _, tl := range tls {
        angle := tl.angle - theta
        dc.MoveTo(tl.x, tl.y)
        ord := tl.tt
        for i := 0; i < 3; i++ {
            x := tl.x + dist[ord][i]*tl.size*math.Cos(angle)
            y := tl.y - dist[ord][i]*tl.size*math.Sin(angle)
            dc.LineTo(x, y)
            angle += theta
        }
        dc.ClosePath()
        if ord == kite {
            dc.SetHexColor("FFA500") 
        } else {
            dc.SetHexColor("FFFF00") 
        }
        dc.FillPreserve()
        dc.SetHexColor("A9A9A9") 
        dc.SetLineWidth(1)
        dc.Stroke()
    }
}

func main() {
    w, h := 700, 450
    dc := gg.NewContext(w, h)
    dc.SetRGB(1, 1, 1)
    dc.Clear()
    tiles := deflateTiles(setupPrototiles(w, h), 5)
    drawTiles(dc, tiles)
    dc.SavePNG("penrose_tiling.png")
}
Task: Recursive descent parser generator




Go: package main

import (
    "fmt"
    "go/ast"
    "go/parser"
    "log"
)

func labelStr(label int) string {
    return fmt.Sprintf("_%04d", label)
}

type binexp struct {
    op, left, right string
    kind, index     int
}

func main() {
    x := "(one + two) * three - four * five"
    fmt.Println("Expression to parse: ", x)
    f, err := parser.ParseExpr(x)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println("\nThe abstract syntax tree for this expression:")
    ast.Print(nil, f)

    fmt.Println("\nThe corresponding three-address code:")
    var binexps []binexp
    
    ast.Inspect(f, func(n ast.Node) bool {
        switch x := n.(type) {
        case *ast.BinaryExpr:
            sx, ok1 := x.X.(*ast.Ident)
            sy, ok2 := x.Y.(*ast.Ident)
            op := x.Op.String()
            if ok1 && ok2 {
                binexps = append(binexps, binexp{op, sx.Name, sy.Name, 3, 0})
            } else if !ok1 && ok2 {
                binexps = append(binexps, binexp{op, "<addr>", sy.Name, 2, 0})
            } else if ok1 && !ok2 {
                binexps = append(binexps, binexp{op, sx.Name, "<addr>", 1, 0})
            } else {
                binexps = append(binexps, binexp{op, "<addr>", "<addr>", 0, 0})
            }
        }
        return true
    })

    for i := 0; i < len(binexps); i++ {
        binexps[i].index = i
    }

    label, last := 0, -1
    var ops, args []binexp
    var labels []string
    for i, be := range binexps {
        if be.kind == 0 {
            ops = append(ops, be)
        }
        if be.kind != 3 {
            continue
        }
        label++
        ls := labelStr(label)
        fmt.Printf("    %s = %s %s %s\n", ls, be.left, be.op, be.right)
        for j := i - 1; j > last; j-- {
            be2 := binexps[j]
            if be2.kind == 2 {
                label++
                ls2 := labelStr(label)
                fmt.Printf("    %s = %s %s %s\n", ls2, ls, be2.op, be2.right)
                ls = ls2
                be = be2
            } else if be2.kind == 1 {
                label++
                ls2 := labelStr(label)
                fmt.Printf("    %s = %s %s %s\n", ls2, be2.left, be2.op, ls)
                ls = ls2
                be = be2
            }
        }
        args = append(args, be)
        labels = append(labels, ls)
        lea, leo := len(args), len(ops)
        for lea >= 2 {
            if i < len(binexps)-1 && args[lea-2].index <= ops[leo-1].index {
                break
            }
            label++
            ls2 := labelStr(label)
            fmt.Printf("    %s = %s %s %s\n", ls2, labels[lea-2], ops[leo-1].op, labels[lea-1])
            ops = ops[0 : leo-1]
            args = args[0 : lea-1]
            labels = labels[0 : lea-1]
            lea--
            leo--
            args[lea-1] = be
            labels[lea-1] = ls2
        }
        last = i
    }
}
Task: Generalised floating point addition




Go: package main

import (
    "fmt"
    "math/big"
)

func repeatedAdd(bf *big.Float, times int) *big.Float {
    if times < 2 {
        return bf
    }
    var sum big.Float
    for i := 0; i < times; i++ {
        sum.Add(&sum, bf)
    }
    return &sum
}

func main() {
    s := "12345679"
    t := "123456790"
    e := 63
    var bf, extra big.Float
    for n := -7; n <= 21; n++ {
        bf.SetString(fmt.Sprintf("%se%d", s, e))
        extra.SetString(fmt.Sprintf("1e%d", e))
        bf = *repeatedAdd(&bf, 81)
        bf.Add(&bf, &extra)
        fmt.Printf("%2d : %s\n", n, bf.String())
        s = t + s
        e -= 9
    }
}
Task: Quoting constructs




Go: package main

import (
    "fmt"
    "os"
    "regexp"
    "strconv"
)








var (
    rl1 = 'a'
    rl2 = '\'' 
)



var (
    is1 = "abc"
    is2 = "\"ab\tc\"" 
)







var (
    rs1 = `
first"
second'
third"
`
    rs2 = `This is one way of including a ` + "`" + ` in a raw string literal.`
    rs3 = `\d+` 
)

func main() {
    fmt.Println(rl1, rl2) 
    fmt.Println(is1, is2)
    fmt.Println(rs1)
    fmt.Println(rs2)
    re := regexp.MustCompile(rs3)
    fmt.Println(re.FindString("abcd1234efgh"))

    

    
    n := 3
    fmt.Printf("\nThere are %d quoting constructs in Go.\n", n)

    
    
    s := "constructs"
    fmt.Println("There are", n, "quoting", s, "in Go.")

    
    
    mapper := func(placeholder string) string {
        switch placeholder {
        case "NUMBER":
            return strconv.Itoa(n)
        case "TYPES":
            return s
        }
        return ""
    }
    fmt.Println(os.Expand("There are ${NUMBER} quoting ${TYPES} in Go.", mapper))
}
Task: Count the coins_0-1




Go: package main

import "fmt"

var cnt = 0  
var cnt2 = 0 
var wdth = 0 

func factorial(n int) int {
    prod := 1
    for i := 2; i <= n; i++ {
        prod *= i
    }
    return prod
}

func count(want int, used []int, sum int, have, uindices, rindices []int) {
    if sum == want {
        cnt++
        cnt2 += factorial(len(used))
        if cnt < 11 {
            uindicesStr := fmt.Sprintf("%v", uindices)
            fmt.Printf("  indices %*s => used %v\n", wdth, uindicesStr, used)
        }
    } else if sum < want && len(have) != 0 {
        thisCoin := have[0]
        index := rindices[0]
        rest := have[1:]
        rindices := rindices[1:]
        count(want, append(used, thisCoin), sum+thisCoin, rest,
            append(uindices, index), rindices)
        count(want, used, sum, rest, uindices, rindices)
    }
}

func countCoins(want int, coins []int, width int) {
    fmt.Printf("Sum %d from coins %v\n", want, coins)
    cnt = 0
    cnt2 = 0
    wdth = -width
    rindices := make([]int, len(coins))
    for i := range rindices {
        rindices[i] = i
    }
    count(want, []int{}, 0, coins, []int{}, rindices)
    if cnt > 10 {
        fmt.Println("  .......")
        fmt.Println("  (only the first 10 ways generated are shown)")
    }
    fmt.Println("Number of ways - order unimportant :", cnt, "(as above)")
    fmt.Println("Number of ways - order important   :", cnt2, "(all perms of above indices)\n")
}

func main() {
    countCoins(6, []int{1, 2, 3, 4, 5}, 7)
    countCoins(6, []int{1, 1, 2, 3, 3, 4, 5}, 9)
    countCoins(40, []int{1, 2, 3, 4, 5, 5, 5, 5, 15, 15, 10, 10, 10, 10, 25, 100}, 20)
}
Task: Meissel–Mertens constant




Go: package main

import (
    "fmt"
    "math"
    "rcu"
)

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

func main() {
    const euler = 0.57721566490153286
    primes := rcu.Primes(1 << 31)
    pc := len(primes)
    sum := 0.0
    fmt.Println("Primes added         M")
    fmt.Println("------------  --------------")
    for i, p := range primes {
        rp := 1.0 / float64(p)
        sum += math.Log(1.0-rp) + rp
        c := i + 1
        if (c%1e7) == 0 || c == pc {
            fmt.Printf("%11s   %0.12f\n", rcu.Commatize(c), sum+euler)
        }
    }
}
Task: Discrete Fourier transform




Go: package main

import (
    "fmt"
    "math"
    "math/cmplx"
)

func dft(x []complex128) []complex128 {
    N := len(x)
    y := make([]complex128, N)
    for k := 0; k < N; k++ {
        for n := 0; n < N; n++ {
            t := -1i * 2 * complex(math.Pi*float64(k)*float64(n)/float64(N), 0)
            y[k] += x[n] * cmplx.Exp(t)
        }
    }
    return y
}

func idft(y []complex128) []float64 {
    N := len(y)
    x := make([]complex128, N)
    for n := 0; n < N; n++ {
        for k := 0; k < N; k++ {
            t := 1i * 2 * complex(math.Pi*float64(k)*float64(n)/float64(N), 0)
            x[n] += y[k] * cmplx.Exp(t)
        }
        x[n] /= complex(float64(N), 0)
        
        if math.Abs(imag(x[n])) < 1e-14 {
            x[n] = complex(real(x[n]), 0)
        }
    }
    z := make([]float64, N)
    for i, c := range x {
        z[i] = float64(real(c))
    }
    return z
}

func main() {
    z := []float64{2, 3, 5, 7, 11}
    x := make([]complex128, len(z))
    fmt.Println("Original sequence:", z)
    for i, n := range z {
        x[i] = complex(n, 0)
    }
    y := dft(x)
    fmt.Println("\nAfter applying the Discrete Fourier Transform:")
    fmt.Printf("%0.14g", y)
    fmt.Println("\n\nAfter applying the Inverse Discrete Fourier Transform to the above transform:")
    z = idft(y)
    fmt.Printf("%0.14g", z)
    fmt.Println()
}
Task: Triangular numbers




Go: package main

import (
    "fmt"
    "github.com/ALTree/bigfloat"
    "math/big"
    "rcu"
)

func main() {
    t := make([]int, 30)
    for n := 1; n < 30; n++ {
        t[n] = t[n-1] + n
    }
    fmt.Println("The first 30 triangular numbers are:")
    rcu.PrintTable(t, 6, 3, false)

    for n := 1; n < 30; n++ {
        t[n] += t[n-1]
    }
    fmt.Println("\nThe first 30 tetrahedral numbers are:")
    rcu.PrintTable(t, 6, 4, false)

    for n := 1; n < 30; n++ {
        t[n] += t[n-1]
    }
    fmt.Println("\nThe first 30 pentatopic numbers are:")
    rcu.PrintTable(t, 6, 5, false)

    for r := 5; r <= 12; r++ {
        for n := 1; n < 30; n++ {
            t[n] += t[n-1]
        }
    }
    fmt.Println("\nThe first 30 12-simplex numbers are:")
    rcu.PrintTable(t, 6, 10, false)

    const prec = 256
    xs := []float64{7140, 21408696, 26728085384, 14545501785001}
    root := new(big.Float)
    temp := new(big.Float)
    temp2 := new(big.Float)
    one := big.NewFloat(1)
    two := big.NewFloat(2)
    three := big.NewFloat(3)
    four := big.NewFloat(4)
    five := big.NewFloat(5)
    eight := big.NewFloat(8)
    nine := big.NewFloat(9)
    twentyFour := big.NewFloat(24)
    twentySeven := big.NewFloat(27)
    third := new(big.Float).SetPrec(prec).Quo(one, three)
    for _, x := range xs {
        bx := big.NewFloat(x).SetPrec(prec)
        fmt.Printf("\nRoots of %d:\n", int(x))
        root.Mul(bx, eight)
        root.Add(root, one)
        root.Sqrt(root)
        root.Sub(root, one)
        root.Quo(root, two)
        fmt.Printf("%14s: %.24f\n", "triangular", root)

        temp.Mul(bx, bx)
        temp.Mul(temp, nine)
        temp.Sub(temp, new(big.Float).SetPrec(prec).Quo(one, twentySeven))
        temp.Sqrt(temp)
        temp2.Mul(bx, three)
        temp2.Sub(temp2, temp)
        temp2 = bigfloat.Pow(temp2, third)
        root.Mul(bx, three)
        root.Add(root, temp)
        root = bigfloat.Pow(root, third)
        root.Add(root, temp2)
        root.Sub(root, one)
        fmt.Printf("%14s: %.24f\n", "tetrahedral", root)

        root.Mul(bx, twentyFour)
        root.Add(root, one)
        root.Sqrt(root)
        root.Mul(root, four)
        root.Add(root, five)
        root.Sqrt(root)
        root.Sub(root, three)
        root.Quo(root, two)
        fmt.Printf("%14s: %.24f\n", "pentatonic", root)
    }
}
Task: Penholodigital squares




Go: package main

import (
    "fmt"
    "math"
    "rcu"
    "strconv"
)

func reverse(s string) string {
    r := make([]byte, len(s))
    for i := 0; i < len(s); i++ {
        r[i] = s[len(s)-1-i]
    }
    return string(r)
}

func main() {
    primes := []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}
    digits := "123456789ABCDEF"
    for b := 9; b <= 16; b++ {
        master := 1
        for d := 1; d < b; d++ {
            master *= primes[d-1]
        }
        var phd []int
        smin, _ := strconv.ParseInt(digits[0:b-1], b, 64)
        min := int(math.Ceil(math.Sqrt(float64(smin))))
        smax, _ := strconv.ParseInt(reverse(digits[0:b-1]), b, 64)
        max := int(math.Floor(math.Sqrt(float64(smax))))
        factors := rcu.PrimeFactors(b - 1)
        div := factors[len(factors)-1]
        for i := min; i <= max; i++ {
            if (i % div) != 0 {
                continue
            }
            sq := i * i
            digs := rcu.Digits(sq, b)
            containsZero := false
            key := 1
            for _, dig := range digs {
                if dig == 0 {
                    containsZero = true
                    break
                }
                key *= primes[dig-1]
            }
            if containsZero {
                continue
            }
            if key == master {
                phd = append(phd, i)
            }
        }
        fmt.Println("There is a total of", len(phd), "penholodigital squares in base", b, "\b:")
        if b > 13 {
            phd = []int{phd[0], phd[len(phd)-1]}
        }
        for i := 0; i < len(phd); i++ {
            sq2 := phd[i] * phd[i]
            fmt.Printf("%s² = %s  ", strconv.FormatInt(int64(phd[i]), b), strconv.FormatInt(int64(sq2), b))
            if (i+1)%3 == 0 {
                fmt.Println()
            }
        }
        if len(phd)%3 != 0 {
            fmt.Println()
        }
        fmt.Println()
    }
}