WeixiangYan/CodeTransOcean huggingface dataset:
Task: Prime numbers which contain 123




Go: package main

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

func main() {
    limit := 100_000
    primes := rcu.Primes(limit * 10)
    var results []int
    for _, p := range primes {
        if p < 1000 || p > 99999 {
            continue
        }
        ps := fmt.Sprintf("%s", p)
        if strings.Contains(ps, "123") {
            results = append(results, p)
        }
    }
    climit := rcu.Commatize(limit)
    fmt.Printf("Primes under %s which contain '123' when expressed in decimal:\n", climit)
    for i, p := range results {
        fmt.Printf("%7s ", rcu.Commatize(p))
        if (i+1)%10 == 0 {
            fmt.Println()
        }
    }
    fmt.Println("\n\nFound", len(results), "such primes under", climit, "\b.")

    limit = 1_000_000
    climit = rcu.Commatize(limit)
    count := len(results)
    for _, p := range primes {
        if p < 100_000 {
            continue
        }
        ps := fmt.Sprintf("%s", p)
        if strings.Contains(ps, "123") {
            count++
        }
    }
    fmt.Println("\nFound", count, "such primes under", climit, "\b.")
}
Task: Prime triplets




Go: package main

import (
    "fmt"
    "rcu"
)

func main() {
    c := rcu.PrimeSieve(5505, false)
    var triples [][3]int
    fmt.Println("Prime triplets: p, p + 2, p + 6 where p < 5,500:")
    for i := 3; i < 5500; i += 2 {
        if !c[i] && !c[i+2] && !c[i+6] {
            triples = append(triples, [3]int{i, i + 2, i + 6})
        }
    }
    for _, triple := range triples {
        var t [3]string
        for i := 0; i < 3; i++ {
            t[i] = rcu.Commatize(triple[i])
        }
        fmt.Printf("%5s  %5s  %5s\n", t[0], t[1], t[2])
    }
    fmt.Println("\nFound", len(triples), "such prime triplets.")
}
Task: Neighbour primes




Go: package main

import (
    "fmt"
    "rcu"
)

func main() {
    primes := rcu.Primes(504)
    var nprimes []int
    fmt.Println("Neighbour primes < 500:")
    for i := 0; i < len(primes)-1; i++ {
        p := primes[i]*primes[i+1] + 2
        if rcu.IsPrime(p) {
            nprimes = append(nprimes, primes[i])
        }
    }
    rcu.PrintTable(nprimes, 10, 3, false)
    fmt.Println("\nFound", len(nprimes), "such primes.")
}
Task: Collect and sort square numbers in ascending order from three lists




Go: package main

import (
    "fmt"
    "math"
    "sort"
)

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

func main() {
    lists := [][]int{
        {3, 4, 34, 25, 9, 12, 36, 56, 36},
        {2, 8, 81, 169, 34, 55, 76, 49, 7},
        {75, 121, 75, 144, 35, 16, 46, 35},
    }
    var squares []int
    for _, list := range lists {
        for _, e := range list {
            if isSquare(e) {
                squares = append(squares, e)
            }
        }
    }
    sort.Ints(squares)
    fmt.Println(squares)
}
Task: Composite numbers k with no single digit factors whose factors are all substrings of k




Go: package main

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

func main() {
    count := 0
    k := 11 * 11
    var res []int
    for count < 20 {
        if k%3 == 0 || k%5 == 0 || k%7 == 0 {
            k += 2
            continue
        }
        factors := rcu.PrimeFactors(k)
        if len(factors) > 1 {
            s := strconv.Itoa(k)
            includesAll := true
            prev := -1
            for _, f := range factors {
                if f == prev {
                    continue
                }
                fs := strconv.Itoa(f)
                if strings.Index(s, fs) == -1 {
                    includesAll = false
                    break
                }
            }
            if includesAll {
                res = append(res, k)
                count++
            }
        }
        k += 2
    }
    for _, e := range res[0:10] {
        fmt.Printf("%10s ", rcu.Commatize(e))
    }
    fmt.Println()
    for _, e := range res[10:20] {
        fmt.Printf("%10s ", rcu.Commatize(e))
    }
    fmt.Println()
}
Task: Magic constant




Go: package main

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

func magicConstant(n int) int {
    return (n*n + 1) * n / 2
}

var ss = []string{
    "\u2070", "\u00b9", "\u00b2", "\u00b3", "\u2074",
    "\u2075", "\u2076", "\u2077", "\u2078", "\u2079",
}

func superscript(n int) string {
    if n < 10 {
        return ss[n]
    }
    if n < 20 {
        return ss[1] + ss[n-10]
    }
    return ss[2] + ss[0]
}

func main() {
    fmt.Println("First 20 magic constants:")
    for n := 3; n <= 22; n++ {
        fmt.Printf("%5d ", magicConstant(n))
        if (n-2)%10 == 0 {
            fmt.Println()
        }
    }

    fmt.Println("\n1,000th magic constant:", rcu.Commatize(magicConstant(1002)))

    fmt.Println("\nSmallest order magic square with a constant greater than:")
    for i := 1; i <= 20; i++ {
        goal := math.Pow(10, float64(i))
        order := int(math.Cbrt(goal*2)) + 1
        fmt.Printf("10%-2s : %9s\n", superscript(i), rcu.Commatize(order))
    }
}
Task: Cullen and Woodall numbers




Go: package main

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

func cullen(n uint) *big.Int {
    one := big.NewInt(1)
    bn := big.NewInt(int64(n))
    res := new(big.Int).Lsh(one, n)
    res.Mul(res, bn)
    return res.Add(res, one)
}

func woodall(n uint) *big.Int {
    res := cullen(n)
    return res.Sub(res, big.NewInt(2))
}

func main() {
    fmt.Println("First 20 Cullen numbers (n * 2^n + 1):")
    for n := uint(1); n <= 20; n++ {
        fmt.Printf("%d ", cullen(n))
    }

    fmt.Println("\n\nFirst 20 Woodall numbers (n * 2^n - 1):")
    for n := uint(1); n <= 20; n++ {
        fmt.Printf("%d ", woodall(n))
    }

    fmt.Println("\n\nFirst 5 Cullen primes (in terms of n):")
    count := 0
    for n := uint(1); count < 5; n++ {
        cn := cullen(n)
        if cn.ProbablyPrime(15) {
            fmt.Printf("%d ", n)
            count++
        }
    }

    fmt.Println("\n\nFirst 12 Woodall primes (in terms of n):")
    count = 0
    for n := uint(1); count < 12; n++ {
        cn := woodall(n)
        if cn.ProbablyPrime(15) {
            fmt.Printf("%d ", n)
            count++
        }
    }
    fmt.Println()
}
Task: Long literals, with continuations




Go: package main

import (
    "fmt"
    "regexp"
    "strings"
)




var elements = `
    hydrogen     helium        lithium      beryllium
    boron        carbon        nitrogen     oxygen
    fluorine     neon          sodium       magnesium
    aluminum     silicon       phosphorous  sulfur
    chlorine     argon         potassium    calcium
    scandium     titanium      vanadium     chromium
    manganese    iron          cobalt       nickel
    copper       zinc          gallium      germanium
    arsenic      selenium      bromine      krypton
    rubidium     strontium     yttrium      zirconium
    niobium      molybdenum    technetium   ruthenium
    rhodium      palladium     silver       cadmium
    indium       tin           antimony     tellurium
    iodine       xenon         cesium       barium
    lanthanum    cerium        praseodymium neodymium
    promethium   samarium      europium     gadolinium
    terbium      dysprosium    holmium      erbium
    thulium      ytterbium     lutetium     hafnium
    tantalum     tungsten      rhenium      osmium
    iridium      platinum      gold         mercury
    thallium     lead          bismuth      polonium
    astatine     radon         francium     radium
    actinium     thorium       protactinium uranium
    neptunium    plutonium     americium    curium
    berkelium    californium   einsteinium  fermium
    mendelevium  nobelium      lawrencium   rutherfordium
    dubnium      seaborgium    bohrium      hassium
    meitnerium   darmstadtium  roentgenium  copernicium
    nihonium     flerovium     moscovium    livermorium
    tennessine   oganesson
`

func main() {
    lastRevDate := "March 24th, 2020"
    re := regexp.MustCompile(`\s+`) 
    els := re.Split(strings.TrimSpace(elements), -1)
    numEls := len(els)
    
    elements2 := strings.Join(els, " ")
    
    fmt.Println("Last revision Date: ", lastRevDate)
    fmt.Println("Number of elements: ", numEls)
    
    
    lix := strings.LastIndex(elements2, " ") 
    fmt.Println("Last element      : ", elements2[lix+1:])
}
Task: Find minimum number of coins that make a given value




Go: package main

import "fmt"

func main() {
    denoms := []int{200, 100, 50, 20, 10, 5, 2, 1}
    coins := 0
    amount := 988
    remaining := 988
    fmt.Println("The minimum number of coins needed to make a value of", amount, "is as follows:")
    for _, denom := range denoms {
        n := remaining / denom
        if n > 0 {
            coins += n
            fmt.Printf("  %3d x %d\n", denom, n)
            remaining %= denom
            if remaining == 0 {
                break
            }
        }
    }
    fmt.Println("\nA total of", coins, "coins in all.")
}
Task: Longest palindromic substrings




Go: package main

import (
    "fmt"
    "sort"
)

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

func longestPalSubstring(s string) []string {
    var le = len(s)
    if le <= 1 {
        return []string{s}
    }
    targetLen := le
    var longest []string
    i := 0
    for {
        j := i + targetLen - 1
        if j < le {
            ss := s[i : j+1]
            if reverse(ss) == ss {
                longest = append(longest, ss)
            }
            i++
        } else {
            if len(longest) > 0 {
                return longest
            }
            i = 0
            targetLen--
        }
    }
    return longest
}

func distinct(sa []string) []string {
    sort.Strings(sa)
    duplicated := make([]bool, len(sa))
    for i := 1; i < len(sa); i++ {
        if sa[i] == sa[i-1] {
            duplicated[i] = true
        }
    }
    var res []string
    for i := 0; i < len(sa); i++ {
        if !duplicated[i] {
            res = append(res, sa[i])
        }
    }
    return res
}

func main() {
    strings := []string{"babaccd", "rotator", "reverse", "forever", "several", "palindrome", "abaracadaraba"}
    fmt.Println("The palindromic substrings having the longest length are:")
    for _, s := range strings {
        longest := distinct(longestPalSubstring(s))
        fmt.Printf("  %-13s Length %d -> %v\n", s, len(longest[0]), longest)
    }
}
Task: Palindromic primes in base 16




Go: package main

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

func reverse(s string) string {
    chars := []rune(s)
    for i, j := 0, len(chars)-1; i < j; i, j = i+1, j-1 {
        chars[i], chars[j] = chars[j], chars[i]
    }
    return string(chars)
}

func main() {
    fmt.Println("Primes < 500 which are palindromic in base 16:")
    primes := rcu.Primes(500)
    count := 0
    for _, p := range primes {
        hp := strconv.FormatInt(int64(p), 16)
        if hp == reverse(hp) {
            fmt.Printf("%3s ", strings.ToUpper(hp))
            count++
            if count%5 == 0 {
                fmt.Println()
            }
        }
    }
    fmt.Println("\n\nFound", count, "such primes.")
}
Task: Find squares n where n+1 is prime




Go: package main

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

func main() {
    var squares []int
    limit := int(math.Sqrt(1000))
    i := 1
    for i <= limit {
        n := i * i
        if rcu.IsPrime(n + 1) {
            squares = append(squares, n)
        }
        if i == 1 {
            i = 2
        } else {
            i += 2
        }
    }
    fmt.Println("There are", len(squares), "square numbers 'n' where 'n+1' is prime, viz:")
    fmt.Println(squares)
}
Task: Read a file character by character_UTF8




Go: package main

import (
    "bufio"
    "fmt"
    "io"
    "os"
)

func Runer(r io.RuneReader) func() (rune, error) {
    return func() (r rune, err error) {
        r, _, err = r.ReadRune()
        return
    }
}

func main() {
    runes := Runer(bufio.NewReader(os.Stdin))
    for r, err := runes(); err != nil; r,err = runes() {
        fmt.Printf("%c", r)
    }
}
Task: Window management




Go: package main

import (
    "github.com/gotk3/gotk3/gtk"
    "log"
    "time"
)

func check(err error, msg string) {
    if err != nil {
        log.Fatal(msg, err)
    }
}

func main() {
    gtk.Init(nil)

    window, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
    check(err, "Unable to create window:")
    window.SetResizable(true)
    window.SetTitle("Window management")
    window.SetBorderWidth(5)
    window.Connect("destroy", func() {
        gtk.MainQuit()
    })

    stackbox, err := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 10)
    check(err, "Unable to create stack box:")

    bmax, err := gtk.ButtonNewWithLabel("Maximize")
    check(err, "Unable to create maximize button:")
    bmax.Connect("clicked", func() {
        window.Maximize()
    })

    bunmax, err := gtk.ButtonNewWithLabel("Unmaximize")
    check(err, "Unable to create unmaximize button:")
    bunmax.Connect("clicked", func() {
        window.Unmaximize()
    })

    bicon, err := gtk.ButtonNewWithLabel("Iconize")
    check(err, "Unable to create iconize button:")
    bicon.Connect("clicked", func() {
        window.Iconify()
    })

    bdeicon, err := gtk.ButtonNewWithLabel("Deiconize")
    check(err, "Unable to create deiconize button:")
    bdeicon.Connect("clicked", func() {
        window.Deiconify()
    })

    bhide, err := gtk.ButtonNewWithLabel("Hide")
    check(err, "Unable to create hide button:")
    bhide.Connect("clicked", func() {
        
        window.Hide() 
        time.Sleep(10 * time.Second)
        window.Show()
    })

    bshow, err := gtk.ButtonNewWithLabel("Show")
    check(err, "Unable to create show button:")
    bshow.Connect("clicked", func() {
        window.Show()
    })

    bmove, err := gtk.ButtonNewWithLabel("Move")
    check(err, "Unable to create move button:")
    isShifted := false
    bmove.Connect("clicked", func() {
        w, h := window.GetSize()
        if isShifted {
            window.Move(w-10, h-10)
        } else {
            window.Move(w+10, h+10)
        }
        isShifted = !isShifted
    })

    bquit, err := gtk.ButtonNewWithLabel("Quit")
    check(err, "Unable to create quit button:")
    bquit.Connect("clicked", func() {
        window.Destroy()
    })

    stackbox.PackStart(bmax, true, true, 0)
    stackbox.PackStart(bunmax, true, true, 0)
    stackbox.PackStart(bicon, true, true, 0)
    stackbox.PackStart(bdeicon, true, true, 0)
    stackbox.PackStart(bhide, true, true, 0)
    stackbox.PackStart(bshow, true, true, 0)
    stackbox.PackStart(bmove, true, true, 0)
    stackbox.PackStart(bquit, true, true, 0)

    window.Add(stackbox)
    window.ShowAll()
    gtk.Main()
}
Task: Galton box animation




Go: package main

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

const boxW = 41      
const boxH = 37      
const pinsBaseW = 19 
const nMaxBalls = 55 

const centerH = pinsBaseW + (boxW-pinsBaseW*2+1)/2 - 1

const (
    empty  = ' '
    ball   = 'o'
    wall   = '|'
    corner = '+'
    floor  = '-'
    pin    = '.'
)

type Ball struct{ x, y int }

func newBall(x, y int) *Ball {
    if box[y][x] != empty {
        panic("Tried to create a new ball in a non-empty cell. Program terminated.")
    }
    b := Ball{x, y}
    box[y][x] = ball
    return &b
}

func (b *Ball) doStep() {
    if b.y <= 0 {
        return 
    }
    cell := box[b.y-1][b.x]
    switch cell {
    case empty:
        box[b.y][b.x] = empty
        b.y--
        box[b.y][b.x] = ball
    case pin:
        box[b.y][b.x] = empty
        b.y--
        if box[b.y][b.x-1] == empty && box[b.y][b.x+1] == empty {
            b.x += rand.Intn(2)*2 - 1
            box[b.y][b.x] = ball
            return
        } else if box[b.y][b.x-1] == empty {
            b.x++
        } else {
            b.x--
        }
        box[b.y][b.x] = ball
    default:
        
    }
}

type Cell = byte


var box [boxH][boxW]Cell

func initializeBox() {
    
    box[0][0] = corner
    box[0][boxW-1] = corner
    for i := 1; i < boxW-1; i++ {
        box[0][i] = floor
    }
    for i := 0; i < boxW; i++ {
        box[boxH-1][i] = box[0][i]
    }

    
    for r := 1; r < boxH-1; r++ {
        box[r][0] = wall
        box[r][boxW-1] = wall
    }

    
    for i := 1; i < boxH-1; i++ {
        for j := 1; j < boxW-1; j++ {
            box[i][j] = empty
        }
    }

    
    for nPins := 1; nPins <= pinsBaseW; nPins++ {
        for p := 0; p < nPins; p++ {
            box[boxH-2-nPins][centerH+1-nPins+p*2] = pin
        }
    }
}

func drawBox() {
    for r := boxH - 1; r >= 0; r-- {
        for c := 0; c < boxW; c++ {
            fmt.Printf("%c", box[r][c])
        }
        fmt.Println()
    }
}

func main() {
    rand.Seed(time.Now().UnixNano())
    initializeBox()
    var balls []*Ball
    for i := 0; i < nMaxBalls+boxH; i++ {
        fmt.Println("\nStep", i, ":")
        if i < nMaxBalls {
            balls = append(balls, newBall(centerH, boxH-2)) 
        }
        drawBox()

        
        
        for _, b := range balls {
            b.doStep()
        }
    }
}
Task: Primes - allocate descendants to their ancestors




Go: package main

import (
    "fmt"
    "sort"
)

func getPrimes(max int) []int {
    if max < 2 {
        return []int{}
    }
    lprimes := []int{2}
outer:
    for x := 3; x <= max; x += 2 {
        for _, p := range lprimes {
            if x%p == 0 {
                continue outer
            }
        }
        lprimes = append(lprimes, x)
    }
    return lprimes
}

func main() {
    const maxSum = 99
    descendants := make([][]int64, maxSum+1)
    ancestors := make([][]int, maxSum+1)
    for i := 0; i <= maxSum; i++ {
        descendants[i] = []int64{}
        ancestors[i] = []int{}
    }
    primes := getPrimes(maxSum)

    for _, p := range primes {
        descendants[p] = append(descendants[p], int64(p))
        for s := 1; s < len(descendants)-p; s++ {
            temp := make([]int64, len(descendants[s]))
            for i := 0; i < len(descendants[s]); i++ {
                temp[i] = int64(p) * descendants[s][i]
            }
            descendants[s+p] = append(descendants[s+p], temp...)
        }
    }

    for _, p := range append(primes, 4) {
        le := len(descendants[p])
        if le == 0 {
            continue
        }
        descendants[p][le-1] = 0
        descendants[p] = descendants[p][:le-1]
    }
    total := 0

    for s := 1; s <= maxSum; s++ {
        x := descendants[s]
        sort.Slice(x, func(i, j int) bool {
            return x[i] < x[j]
        })
        total += len(descendants[s])
        index := 0
        for ; index < len(descendants[s]); index++ {
            if descendants[s][index] > int64(maxSum) {
                break
            }
        }
        for _, d := range descendants[s][:index] {
            ancestors[d] = append(ancestors[s], s)
        }
        if (s >= 21 && s <= 45) || (s >= 47 && s <= 73) || (s >= 75 && s < maxSum) {
            continue
        }
        temp := fmt.Sprintf("%v", ancestors[s])
        fmt.Printf("%2d: %d Ancestor(s): %-14s", s, len(ancestors[s]), temp)
        le := len(descendants[s])
        if le <= 10 {
            fmt.Printf("%5d Descendant(s): %v\n", le, descendants[s])
        } else {
            fmt.Printf("%5d Descendant(s): %v\b ...]\n", le, descendants[s][:10])
        }
    }
    fmt.Println("\nTotal descendants", total)
}
Task: Smallest square that begins with n




Go: package main

import (
    "fmt"
    "math"
)

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

func main() {
    var squares []int
outer:
    for i := 1; i < 50; i++ {
        if isSquare(i) {
            squares = append(squares, i)
        } else {
            n := i
            limit := 10
            for {
                n *= 10
                for j := 0; j < limit; j++ {
                    s := n + j
                    if isSquare(s) {
                        squares = append(squares, s)
                        continue outer
                    }
                }
                limit *= 10
            }
        }
    }
    fmt.Println("Smallest squares that begin with 'n' in [1, 49]:")
    for i, s := range squares {
        fmt.Printf("%5d  ", s)
        if ((i + 1) % 10) == 0 {
            fmt.Println()
        }
    }
    if (len(squares) % 10) != 0 {
        fmt.Println()
    }
}
Task: Sorting Algorithms_Circle Sort




Go: package main

import "fmt"

func circleSort(a []int, lo, hi, swaps int) int {
    if lo == hi {
        return swaps
    }
    high, low := hi, lo
    mid := (hi - lo) / 2
    for lo < hi {
        if a[lo] > a[hi] {
            a[lo], a[hi] = a[hi], a[lo]
            swaps++
        }
        lo++
        hi--
    }
    if lo == hi {
        if a[lo] > a[hi+1] {
            a[lo], a[hi+1] = a[hi+1], a[lo]
            swaps++
        }
    }
    swaps = circleSort(a, low, low+mid, swaps)
    swaps = circleSort(a, low+mid+1, high, swaps)
    return swaps
}

func main() {
    aa := [][]int{
        {6, 7, 8, 9, 2, 5, 3, 4, 1},
        {2, 14, 4, 6, 8, 1, 3, 5, 7, 11, 0, 13, 12, -1},
    }
    for _, a := range aa {
        fmt.Printf("Original: %v\n", a)
        for circleSort(a, 0, len(a)-1, 0) != 0 {
            
        }
        fmt.Printf("Sorted  : %v\n\n", a)
    }
}
Task: Intersecting number wheels




Go: package main

import (
    "fmt"
    "sort"
    "strconv"
)

type wheel struct {
    next   int
    values []string
}

type wheelMap = map[string]wheel

func generate(wheels wheelMap, start string, maxCount int) {
    count := 0
    w := wheels[start]
    for {
        s := w.values[w.next]
        v, err := strconv.Atoi(s)
        w.next = (w.next + 1) % len(w.values)
        wheels[start] = w
        if err == nil {
            fmt.Printf("%d ", v)
            count++
            if count == maxCount {
                fmt.Println("...\n")
                return
            }
        } else {
            for {
                w2 := wheels[s]
                ss := s
                s = w2.values[w2.next]
                w2.next = (w2.next + 1) % len(w2.values)
                wheels[ss] = w2
                v, err = strconv.Atoi(s)
                if err == nil {
                    fmt.Printf("%d ", v)
                    count++
                    if count == maxCount {
                        fmt.Println("...\n")
                        return
                    }
                    break
                }
            }
        }
    }
}

func printWheels(wheels wheelMap) {
    var names []string
    for name := range wheels {
        names = append(names, name)
    }
    sort.Strings(names)
    fmt.Println("Intersecting Number Wheel group:")
    for _, name := range names {
        fmt.Printf("  %s: %v\n", name, wheels[name].values)
    }
    fmt.Print("  Generates:\n    ")
}

func main() {
    wheelMaps := []wheelMap{
        {
            "A": {0, []string{"1", "2", "3"}},
        },
        {
            "A": {0, []string{"1", "B", "2"}},
            "B": {0, []string{"3", "4"}},
        },
        {
            "A": {0, []string{"1", "D", "D"}},
            "D": {0, []string{"6", "7", "8"}},
        },
        {
            "A": {0, []string{"1", "B", "C"}},
            "B": {0, []string{"3", "4"}},
            "C": {0, []string{"5", "B"}},
        },
    }
    for _, wheels := range wheelMaps {
        printWheels(wheels)
        generate(wheels, "A", 20)
    }
}
Task: Color of a screen pixel




Go: package main

import (
    "fmt"
    "github.com/go-vgo/robotgo"
)

func main() {
    
    x, y := robotgo.GetMousePos()

    
    color := robotgo.GetPixelColor(x, y)
    fmt.Printf("Color of pixel at (%d, %d) is 0x%s\n", x, y, color)   
}