WeixiangYan/CodeTransOcean huggingface dataset:
Task: Generate random chess position




Go: package main

import (
    "fmt"
    "math/rand"
    "strconv"
    "strings"
    "time"
)

var grid [8][8]byte

func abs(i int) int {
    if i >= 0 {
        return i
    } else {
        return -i
    }
}

func createFen() string {
    placeKings()
    placePieces("PPPPPPPP", true)
    placePieces("pppppppp", true)
    placePieces("RNBQBNR", false)
    placePieces("rnbqbnr", false)
    return toFen()
}

func placeKings() {
    for {
        r1 := rand.Intn(8)
        c1 := rand.Intn(8)
        r2 := rand.Intn(8)
        c2 := rand.Intn(8)
        if r1 != r2 && abs(r1-r2) > 1 && abs(c1-c2) > 1 {
            grid[r1][c1] = 'K'
            grid[r2][c2] = 'k'
            return
        }
    }
}

func placePieces(pieces string, isPawn bool) {
    numToPlace := rand.Intn(len(pieces))
    for n := 0; n < numToPlace; n++ {
        var r, c int
        for {
            r = rand.Intn(8)
            c = rand.Intn(8)
            if grid[r][c] == '\000' && !(isPawn && (r == 7 || r == 0)) {
                break
            }
        }
        grid[r][c] = pieces[n]
    }
}

func toFen() string {
    var fen strings.Builder
    countEmpty := 0
    for r := 0; r < 8; r++ {
        for c := 0; c < 8; c++ {
            ch := grid[r][c]
            if ch == '\000' {
                ch = '.'
            }
            fmt.Printf("%2c ", ch)
            if ch == '.' {
                countEmpty++
            } else {
                if countEmpty > 0 {
                    fen.WriteString(strconv.Itoa(countEmpty))
                    countEmpty = 0
                }
                fen.WriteByte(ch)
            }
        }
        if countEmpty > 0 {
            fen.WriteString(strconv.Itoa(countEmpty))
            countEmpty = 0
        }
        fen.WriteString("/")
        fmt.Println()
    }
    fen.WriteString(" w - - 0 1")
    return fen.String()
}

func main() {
    rand.Seed(time.Now().UnixNano())
    fmt.Println(createFen())
}
Task: Numbers which are the cube roots of the product of their proper divisors




Go: package main

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

func divisorCount(n int) int {
    k := 1
    if n%2 == 1 {
        k = 2
    }
    count := 0
    sqrt := int(math.Sqrt(float64(n)))
    for i := 1; i <= sqrt; i += k {
        if n%i == 0 {
            count++
            j := n / i
            if j != i {
                count++
            }
        }
    }
    return count
}

func main() {
    var numbers50 []int
    count := 0
    for n := 1; count < 50000; n++ {
        dc := divisorCount(n)
        if n == 1 || dc == 8 {
            count++
            if count <= 50 {
                numbers50 = append(numbers50, n)
                if count == 50 {
                    rcu.PrintTable(numbers50, 10, 3, false)
                }
            } else if count == 500 {
                fmt.Printf("\n500th   : %s", rcu.Commatize(n))
            } else if count == 5000 {
                fmt.Printf("\n5,000th : %s", rcu.Commatize(n))
            } else if count == 50000 {
                fmt.Printf("\n50,000th: %s\n", rcu.Commatize(n))
            }
        }
    }
}
Task: Arithmetic derivative




Go: package main

import (
    "fmt"
    "rcu"
)

func D(n float64) float64 {
    if n < 0 {
        return -D(-n)
    }
    if n < 2 {
        return 0
    }
    var f []int
    if n < 1e19 {
        f = rcu.PrimeFactors(int(n))
    } else {
        g := int(n / 100)
        f = rcu.PrimeFactors(g)
        f = append(f, []int{2, 2, 5, 5}...)
    }
    c := len(f)
    if c == 1 {
        return 1
    }
    if c == 2 {
        return float64(f[0] + f[1])
    }
    d := n / float64(f[0])
    return D(d)*float64(f[0]) + d
}

func main() {
    ad := make([]int, 200)
    for n := -99; n < 101; n++ {
        ad[n+99] = int(D(float64(n)))
    }
    rcu.PrintTable(ad, 10, 4, false)
    fmt.Println()
    pow := 1.0
    for m := 1; m < 21; m++ {
        pow *= 10
        fmt.Printf("D(10^%-2d) / 7 = %.0f\n", m, D(pow)/7)
    }
}
Task: Product of min and max prime factors




Go: package main

import (
    "fmt"
    "rcu"
)

func main() {
    prods := make([]int, 100)
    prods[0] = 1
    for i := 2; i <= 100; i++ {
        factors := rcu.PrimeFactors(i)
        prods[i-1] = factors[0] * factors[len(factors)-1]
    }
    fmt.Println("Product of smallest and greatest prime factors of n for 1 to 100:")
    rcu.PrintTable(prods, 10, 4, false)
}
Task: Special factorials




Go: package main

import (
    "fmt"
    "math/big"
)

func sf(n int) *big.Int {
    if n < 2 {
        return big.NewInt(1)
    }
    sfact := big.NewInt(1)
    fact := big.NewInt(1)
    for i := 2; i <= n; i++ {
        fact.Mul(fact, big.NewInt(int64(i)))
        sfact.Mul(sfact, fact)
    }
    return sfact
}

func H(n int) *big.Int {
    if n < 2 {
        return big.NewInt(1)
    }
    hfact := big.NewInt(1)
    for i := 2; i <= n; i++ {
        bi := big.NewInt(int64(i))
        hfact.Mul(hfact, bi.Exp(bi, bi, nil))
    }
    return hfact
}

func af(n int) *big.Int {
    if n < 1 {
        return new(big.Int)
    }
    afact := new(big.Int)
    fact := big.NewInt(1)
    sign := new(big.Int)
    if n%2 == 0 {
        sign.SetInt64(-1)
    } else {
        sign.SetInt64(1)
    }
    t := new(big.Int)
    for i := 1; i <= n; i++ {
        fact.Mul(fact, big.NewInt(int64(i)))
        afact.Add(afact, t.Mul(fact, sign))
        sign.Neg(sign)
    }
    return afact
}

func ef(n int) *big.Int {
    if n < 1 {
        return big.NewInt(1)
    }
    t := big.NewInt(int64(n))
    return t.Exp(t, ef(n-1), nil)
}

func rf(n *big.Int) int {
    i := 0
    fact := big.NewInt(1)
    for {
        if fact.Cmp(n) == 0 {
            return i
        }
        if fact.Cmp(n) > 0 {
            return -1
        }
        i++
        fact.Mul(fact, big.NewInt(int64(i)))
    }
}

func main() {
    fmt.Println("First 10 superfactorials:")
    for i := 0; i < 10; i++ {
        fmt.Println(sf(i))
    }

    fmt.Println("\nFirst 10 hyperfactorials:")
    for i := 0; i < 10; i++ {
        fmt.Println(H(i))
    }

    fmt.Println("\nFirst 10 alternating factorials:")
    for i := 0; i < 10; i++ {
        fmt.Print(af(i), " ")
    }

    fmt.Println("\n\nFirst 5 exponential factorials:")
    for i := 0; i <= 4; i++ {
        fmt.Print(ef(i), " ")
    }

    fmt.Println("\n\nThe number of digits in 5$ is", len(ef(5).String()))

    fmt.Println("\nReverse factorials:")
    facts := []int64{1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 119}
    for _, fact := range facts {
        bfact := big.NewInt(fact)
        rfact := rf(bfact)
        srfact := fmt.Sprintf("%d", rfact)
        if rfact == -1 {
            srfact = "none"
        }
        fmt.Printf("%4s <- rf(%d)\n", srfact, fact)
    }
}
Task: Pandigital prime




Go: package main

import (
    "fmt"
    "rcu"
)


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


func permutations(input []int) [][]int {
    perms := [][]int{input}
    a := make([]int, len(input))
    copy(a, input)
    var n = len(input) - 1
    for c := 1; c < factorial(n+1); c++ {
        i := n - 1
        j := n
        for a[i] > a[i+1] {
            i--
        }
        for a[j] < a[i] {
            j--
        }
        a[i], a[j] = a[j], a[i]
        j = n
        i += 1
        for i < j {
            a[i], a[j] = a[j], a[i]
            i++
            j--
        }
        b := make([]int, len(input))
        copy(b, a)
        perms = append(perms, b)
    }
    return perms
}

func main() {
outer:
    for _, start := range []int{1, 0} {
        fmt.Printf("The largest pandigital decimal prime which uses all the digits %d..n once is:\n", start)
        for _, n := range []int{7, 4} {
            m := n + 1 - start
            list := make([]int, m)
            for i := 0; i < m; i++ {
                list[i] = i + start
            }
            perms := permutations(list)
            for i := len(perms) - 1; i >= 0; i-- {
                le := len(perms[i])
                if perms[i][le-1]%2 == 0 || perms[i][le-1] == 5 || (start == 0 && perms[i][0] == 0) {
                    continue
                }
                p := 0
                pow := 1
                for j := le - 1; j >= 0; j-- {
                    p += perms[i][j] * pow
                    pow *= 10
                }
                if rcu.IsPrime(p) {
                    fmt.Println(rcu.Commatize(p) + "\n")
                    continue outer
                }
            }
        }
    }
}
Task: Sierpinski square curve




Go: package main

import (
    "github.com/fogleman/gg"
    "github.com/trubitsyn/go-lindenmayer"
    "log"
    "math"
)

const twoPi = 2 * math.Pi

var (
    width  = 770.0
    height = 770.0
    dc     = gg.NewContext(int(width), int(height))
)

var cx, cy, h, theta float64

func main() {
    dc.SetRGB(0, 0, 1) 
    dc.Clear()
    cx, cy = 10, height/2+5
    h = 6
    sys := lindenmayer.Lsystem{
        Variables: []rune{'X'},
        Constants: []rune{'F', '+', '-'},
        Axiom:     "F+XF+F+XF",
        Rules: []lindenmayer.Rule{
            {"X", "XF-F+F-XF+F+XF-F+F-X"},
        },
        Angle: math.Pi / 2, 
    }
    result := lindenmayer.Iterate(&sys, 5)
    operations := map[rune]func(){
        'F': func() {
            newX, newY := cx+h*math.Sin(theta), cy-h*math.Cos(theta)
            dc.LineTo(newX, newY)
            cx, cy = newX, newY
        },
        '+': func() {
            theta = math.Mod(theta+sys.Angle, twoPi)
        },
        '-': func() {
            theta = math.Mod(theta-sys.Angle, twoPi)
        },
    }
    if err := lindenmayer.Process(result, operations); err != nil {
        log.Fatal(err)
    }
    
    operations['+']()
    operations['F']()

    
    dc.SetRGB255(255, 255, 0) 
    dc.SetLineWidth(2)
    dc.Stroke()
    dc.SavePNG("sierpinski_square_curve.png")
}
Task: Rhonda numbers




Go: package main

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

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

func main() {
    for b := 2; b <= 36; b++ {
        if rcu.IsPrime(b) {
            continue
        }
        count := 0
        var rhonda []int
        for n := 1; count < 15; n++ {
            digits := rcu.Digits(n, b)
            if !contains(digits, 0) {
                var anyEven = false
                for _, d := range digits {
                    if d%2 == 0 {
                        anyEven = true
                        break
                    }
                }
                if b != 10 || (contains(digits, 5) && anyEven) {
                    calc1 := 1
                    for _, d := range digits {
                        calc1 *= d
                    }
                    calc2 := b * rcu.SumInts(rcu.PrimeFactors(n))
                    if calc1 == calc2 {
                        rhonda = append(rhonda, n)
                        count++
                    }
                }
            }
        }
        if len(rhonda) > 0 {
            fmt.Printf("\nFirst 15 Rhonda numbers in base %d:\n", b)
            rhonda2 := make([]string, len(rhonda))
            counts2 := make([]int, len(rhonda))
            for i, r := range rhonda {
                rhonda2[i] = fmt.Sprintf("%d", r)
                counts2[i] = len(rhonda2[i])
            }
            rhonda3 := make([]string, len(rhonda))
            counts3 := make([]int, len(rhonda))
            for i, r := range rhonda {
                rhonda3[i] = strconv.FormatInt(int64(r), b)
                counts3[i] = len(rhonda3[i])
            }
            maxLen2 := rcu.MaxInts(counts2)
            maxLen3 := rcu.MaxInts(counts3)
            maxLen := maxLen2
            if maxLen3 > maxLen {
                maxLen = maxLen3
            }
            maxLen++
            fmt.Printf("In base 10: %*s\n", maxLen, rhonda2)
            fmt.Printf("In base %-2d: %*s\n", b, maxLen, rhonda3)
        }
    }
}
Task: Tropical algebra overloading




Go: package main

import (
    "fmt"
    "log"
    "math"
)

var MinusInf = math.Inf(-1)

type MaxTropical struct{ r float64 }

func newMaxTropical(r float64) MaxTropical {
    if math.IsInf(r, 1) || math.IsNaN(r) {
        log.Fatal("Argument must be a real number or negative infinity.")
    }
    return MaxTropical{r}
}

func (t MaxTropical) eq(other MaxTropical) bool {
    return t.r == other.r
}


func (t MaxTropical) add(other MaxTropical) MaxTropical {
    if t.r == MinusInf {
        return other
    }
    if other.r == MinusInf {
        return t
    }
    return newMaxTropical(math.Max(t.r, other.r))
}


func (t MaxTropical) mul(other MaxTropical) MaxTropical {
    if t.r == 0 {
        return other
    }
    if other.r == 0 {
        return t
    }
    return newMaxTropical(t.r + other.r)
}


func (t MaxTropical) pow(e int) MaxTropical {
    if e < 1 {
        log.Fatal("Exponent must be a positive integer.")
    }
    if e == 1 {
        return t
    }
    p := t
    for i := 2; i <= e; i++ {
        p = p.mul(t)
    }
    return p
}

func (t MaxTropical) String() string {
    return fmt.Sprintf("%g", t.r)
}

func main() {
    
    data := [][]float64{
        {2, -2, 1},
        {-0.001, MinusInf, 0},
        {0, MinusInf, 1},
        {1.5, -1, 0},
        {-0.5, 0, 1},
    }
    for _, d := range data {
        a := newMaxTropical(d[0])
        b := newMaxTropical(d[1])
        if d[2] == 0 {
            fmt.Printf("%s ⊕ %s = %s\n", a, b, a.add(b))
        } else {
            fmt.Printf("%s ⊗ %s = %s\n", a, b, a.mul(b))
        }
    }

    c := newMaxTropical(5)
    fmt.Printf("%s ^ 7 = %s\n", c, c.pow(7))

    d := newMaxTropical(8)
    e := newMaxTropical(7)
    f := c.mul(d.add(e))
    g := c.mul(d).add(c.mul(e))
    fmt.Printf("%s ⊗ (%s ⊕ %s) = %s\n", c, d, e, f)
    fmt.Printf("%s ⊗ %s ⊕ %s ⊗ %s = %s\n", c, d, c, e, g)
    fmt.Printf("%s ⊗ (%s ⊕ %s) == %s ⊗ %s ⊕ %s ⊗ %s is %t\n", c, d, e, c, d, c, e, f.eq(g))
}
Task: Ruth-Aaron numbers




Go: package main

import (
    "fmt"
    "rcu"
)

func prune(a []int) []int {
    prev := a[0]
    b := []int{prev}
    for i := 1; i < len(a); i++ {
        if a[i] != prev {
            b = append(b, a[i])
            prev = a[i]
        }
    }
    return b
}

func main() {
    var resF, resD, resT, factors1 []int
    factors2 := []int{2}
    factors3 := []int{3}
    var sum1, sum2, sum3 int = 0, 2, 3
    var countF, countD, countT int
    for n := 2; countT < 1 || countD < 30 || countF < 30; n++ {
        factors1 = factors2
        factors2 = factors3
        factors3 = rcu.PrimeFactors(n + 2)
        sum1 = sum2
        sum2 = sum3
        sum3 = rcu.SumInts(factors3)
        if countF < 30 && sum1 == sum2 {
            resF = append(resF, n)
            countF++
        }
        if sum1 == sum2 && sum2 == sum3 {
            resT = append(resT, n)
            countT++
        }
        if countD < 30 {
            factors4 := make([]int, len(factors1))
            copy(factors4, factors1)
            factors5 := make([]int, len(factors2))
            copy(factors5, factors2)
            factors4 = prune(factors4)
            factors5 = prune(factors5)
            if rcu.SumInts(factors4) == rcu.SumInts(factors5) {
                resD = append(resD, n)
                countD++
            }
        }
    }
    fmt.Println("First 30 Ruth-Aaron numbers (factors):")
    fmt.Println(resF)
    fmt.Println("\nFirst 30 Ruth-Aaron numbers (divisors):")
    fmt.Println(resD)
    fmt.Println("\nFirst Ruth-Aaron triple (factors):")
    fmt.Println(resT[0])

    resT = resT[:0]
    factors1 = factors1[:0]
    factors2 = factors2[:1]
    factors2[0] = 2
    factors3 = factors3[:1]
    factors3[0] = 3
    countT = 0
    for n := 2; countT < 1; n++ {
        factors1 = factors2
        factors2 = factors3
        factors3 = prune(rcu.PrimeFactors(n + 2))
        sum1 = sum2
        sum2 = sum3
        sum3 = rcu.SumInts(factors3)
        if sum1 == sum2 && sum2 == sum3 {
            resT = append(resT, n)
            countT++
        }
    }
    fmt.Println("\nFirst Ruth-Aaron triple (divisors):")
    fmt.Println(resT[0])
}
Task: Permutations with some identical elements




Go: package main

import "fmt"

func shouldSwap(s []byte, start, curr int) bool {
    for i := start; i < curr; i++ {
        if s[i] == s[curr] {
            return false
        }
    }
    return true
}

func findPerms(s []byte, index, n int, res *[]string) {
    if index >= n {
        *res = append(*res, string(s))
        return
    }
    for i := index; i < n; i++ {
        check := shouldSwap(s, index, i)
        if check {
            s[index], s[i] = s[i], s[index]
            findPerms(s, index+1, n, res)
            s[index], s[i] = s[i], s[index]
        }
    }
}

func createSlice(nums []int, charSet string) []byte {
    var chars []byte
    for i := 0; i < len(nums); i++ {
        for j := 0; j < nums[i]; j++ {
            chars = append(chars, charSet[i])
        }
    }
    return chars
}

func main() {
    var res, res2, res3 []string
    nums := []int{2, 1}
    s := createSlice(nums, "12")
    findPerms(s, 0, len(s), &res)
    fmt.Println(res)
    fmt.Println()

    nums = []int{2, 3, 1}
    s = createSlice(nums, "123")
    findPerms(s, 0, len(s), &res2)
    fmt.Println(res2)
    fmt.Println()

    s = createSlice(nums, "ABC")
    findPerms(s, 0, len(s), &res3)
    fmt.Println(res3)
}
Task: Pisano period




Go: package main

import "fmt"

func gcd(a, b uint) uint {
    if b == 0 {
        return a
    }
    return gcd(b, a%b)
}

func lcm(a, b uint) uint {
    return a / gcd(a, b) * b
}

func ipow(x, p uint) uint {
    prod := uint(1)
    for p > 0 {
        if p&1 != 0 {
            prod *= x
        }
        p >>= 1
        x *= x
    }
    return prod
}


func getPrimes(n uint) []uint {
    var primes []uint
    for i := uint(2); i <= n; i++ {
        div := n / i
        mod := n % i
        for mod == 0 {
            primes = append(primes, i)
            n = div
            div = n / i
            mod = n % i
        }
    }
    return primes
}


func isPrime(n uint) bool {
    switch {
    case n < 2:
        return false
    case n%2 == 0:
        return n == 2
    case n%3 == 0:
        return n == 3
    default:
        d := uint(5)
        for d*d <= n {
            if n%d == 0 {
                return false
            }
            d += 2
            if n%d == 0 {
                return false
            }
            d += 4
        }
        return true
    }
}


func pisanoPeriod(m uint) uint {
    var p, c uint = 0, 1
    for i := uint(0); i < m*m; i++ {
        p, c = c, (p+c)%m
        if p == 0 && c == 1 {
            return i + 1
        }
    }
    return 1
}


func pisanoPrime(p uint, k uint) uint {
    if !isPrime(p) || k == 0 {
        return 0 
    }
    return ipow(p, k-1) * pisanoPeriod(p)
}


func pisano(m uint) uint {
    primes := getPrimes(m)
    primePowers := make(map[uint]uint)
    for _, p := range primes {
        primePowers[p]++
    }
    var pps []uint
    for k, v := range primePowers {
        pps = append(pps, pisanoPrime(k, v))
    }
    if len(pps) == 0 {
        return 1
    }
    if len(pps) == 1 {
        return pps[0]
    }    
    f := pps[0]
    for i := 1; i < len(pps); i++ {
        f = lcm(f, pps[i])
    }
    return f
}

func main() {
    for p := uint(2); p < 15; p++ {
        pp := pisanoPrime(p, 2)
        if pp > 0 {
            fmt.Printf("pisanoPrime(%2d: 2) = %d\n", p, pp)
        }
    }
    fmt.Println()
    for p := uint(2); p < 180; p++ {
        pp := pisanoPrime(p, 1)
        if pp > 0 {
            fmt.Printf("pisanoPrime(%3d: 1) = %d\n", p, pp)
        }
    }
    fmt.Println()
    fmt.Println("pisano(n) for integers 'n' from 1 to 180 are:")
    for n := uint(1); n <= 180; n++ {
        fmt.Printf("%3d ", pisano(n))
        if n != 1 && n%15 == 0 {
            fmt.Println()
        }
    }    
    fmt.Println()
}
Task: Minkowski question-mark function




Go: package main

import (
    "fmt"
    "math"
)

const MAXITER = 151

func minkowski(x float64) float64 {
    if x > 1 || x < 0 {
        return math.Floor(x) + minkowski(x-math.Floor(x))
    }
    p := uint64(x)
    q := uint64(1)
    r := p + 1
    s := uint64(1)
    d := 1.0
    y := float64(p)
    for {
        d = d / 2
        if y+d == y {
            break
        }
        m := p + r
        if m < 0 || p < 0 {
            break
        }
        n := q + s
        if n < 0 {
            break
        }
        if x < float64(m)/float64(n) {
            r = m
            s = n
        } else {
            y = y + d
            p = m
            q = n
        }
    }
    return y + d
}

func minkowskiInv(x float64) float64 {
    if x > 1 || x < 0 {
        return math.Floor(x) + minkowskiInv(x-math.Floor(x))
    }
    if x == 1 || x == 0 {
        return x
    }
    contFrac := []uint32{0}
    curr := uint32(0)
    count := uint32(1)
    i := 0
    for {
        x *= 2
        if curr == 0 {
            if x < 1 {
                count++
            } else {
                i++
                t := contFrac
                contFrac = make([]uint32, i+1)
                copy(contFrac, t)
                contFrac[i-1] = count
                count = 1
                curr = 1
                x--
            }
        } else {
            if x > 1 {
                count++
                x--
            } else {
                i++
                t := contFrac
                contFrac = make([]uint32, i+1)
                copy(contFrac, t)
                contFrac[i-1] = count
                count = 1
                curr = 0
            }
        }
        if x == math.Floor(x) {
            contFrac[i] = count
            break
        }
        if i == MAXITER {
            break
        }
    }
    ret := 1.0 / float64(contFrac[i])
    for j := i - 1; j >= 0; j-- {
        ret = float64(contFrac[j]) + 1.0/ret
    }
    return 1.0 / ret
}

func main() {
    fmt.Printf("%19.16f %19.16f\n", minkowski(0.5*(1+math.Sqrt(5))), 5.0/3.0)
    fmt.Printf("%19.16f %19.16f\n", minkowskiInv(-5.0/9.0), (math.Sqrt(13)-7)/6)
    fmt.Printf("%19.16f %19.16f\n", minkowski(minkowskiInv(0.718281828)),
        minkowskiInv(minkowski(0.1213141516171819)))
}
Task: Distinct palindromes within decimal numbers




Go: package main

import (
    "fmt"
    "sort"
    "strings"
)

func substrings(s string) []string {
    var ss []string
    n := len(s)
    for i := 0; i < n; i++ {
        for j := 1; j <= n-i; j++ {
            ss = append(ss, s[i:i+j])
        }
    }
    return ss
}

func reversed(s string) string {
    var sb strings.Builder
    for i := len(s) - 1; i >= 0; i-- {
        sb.WriteByte(s[i])
    }
    return sb.String()
}

func main() {
    fmt.Println("Number  Palindromes")
    for i := 100; i <= 125; i++ {
        var pals []string
        ss := substrings(fmt.Sprintf("%d", i))
        for _, s := range ss {
            if s == reversed(s) {
                pals = append(pals, s)
            }
        }
        m := make(map[string]bool)
        for _, pal := range pals {
            m[pal] = true
        }
        pals = pals[:0]
        for k := range m {
            pals = append(pals, k)
        }
        sort.Slice(pals, func(i, j int) bool {
            if len(pals[i]) == len(pals[j]) {
                return pals[i] < pals[j]
            }
            return len(pals[i]) < len(pals[j])
        })
        fmt.Printf("%d   %3s\n", i, pals)
    }
    nums := []string{
        "9", "169", "12769", "1238769", "123498769", "12346098769", "1234572098769",
        "123456832098769", "12345679432098769", "1234567905432098769", "123456790165432098769",
        "83071934127905179083", "1320267947849490361205695",
    }
    fmt.Println("\nNumber                    Has no >= 2 digit palindromes")
    for _, num := range nums {
        tmp := substrings(num)
        var ss []string
        for _, t := range tmp {
            if len(t) > 1 {
                ss = append(ss, t)
            }
        }
        none := true
        for _, s := range ss {
            if s == reversed(s) {
                none = false
                break
            }
        }
        fmt.Printf("%-25s %t\n", num, none)
    }
}