WeixiangYan/CodeTransOcean huggingface dataset:
Task: XXXX redacted




Go: package main

import (
    "fmt"
    "github.com/rivo/uniseg"
    "log"
    "regexp"
    "strings"
)

func join(words, seps []string) string {
    lw := len(words)
    ls := len(seps)
    if lw != ls+1 {
        log.Fatal("mismatch between number of words and separators")
    }
    var sb strings.Builder
    for i := 0; i < ls; i++ {
        sb.WriteString(words[i])
        sb.WriteString(seps[i])
    }
    sb.WriteString(words[lw-1])
    return sb.String()
}

func redact(text, word, opts string) {
    var partial, overkill bool
    exp := word
    if strings.IndexByte(opts, 'p') >= 0 {
        partial = true
    }
    if strings.IndexByte(opts, 'o') >= 0 {
        overkill = true
    }
    if strings.IndexByte(opts, 'i') >= 0 {
        exp = `(?i)` + exp
    }
    rgx := regexp.MustCompile(`[\s!-&(-,./:-@[-^{-~]+`) 
    seps := rgx.FindAllString(text, -1)
    words := rgx.Split(text, -1)
    rgx2 := regexp.MustCompile(exp)
    for i, w := range words {
        match := rgx2.FindString(w)
        
        if match == "" || strings.Index(w, match+"\u200d") >= 0 ||
            strings.Index(w, "\u200d"+match) >= 0 {
            continue
        }
        switch {
        case overkill:
            words[i] = strings.Repeat("X", uniseg.GraphemeClusterCount(w))
        case !partial:
            if words[i] == match {
                words[i] = strings.Repeat("X", uniseg.GraphemeClusterCount(w))
            }
        case partial:
            repl := strings.Repeat("X", uniseg.GraphemeClusterCount(word))
            words[i] = rgx2.ReplaceAllLiteralString(w, repl)
        }
    }
    fmt.Printf("%s %s\n\n", opts, join(words, seps))
}

func printResults(text string, allOpts, allWords []string) {
    fmt.Printf("Text: %s\n\n", text)
    for _, word := range allWords {
        fmt.Printf("Redact '%s':\n", word)
        for _, opts := range allOpts {
            redact(text, word, opts)
        }
    }
    fmt.Println()
}

func main() {
    text := `Tom? Toms bottom tomato is in his stomach while playing the "Tom-tom" brand tom-toms. That's so tom.
'Tis very tomish, don't you think?`
    allOpts := []string{"[w|s|n]", "[w|i|n]", "[p|s|n]", "[p|i|n]", "[p|s|o]", "[p|i|o]"}
    allWords := []string{"Tom", "tom", "t"}
    printResults(text, allOpts, allWords)

    text = "🧑 👨 🧔 👨‍👩‍👦"
    allOpts = []string{"[w]"}
    allWords = []string{"👨", "👨‍👩‍👦"}
    printResults(text, allOpts, allWords)

    text = "Argentina🧑🇦🇹  France👨🇫🇷  Germany🧔🇩🇪  Netherlands👨‍👩‍👦🇳🇱"
    allOpts = []string{"[p]", "[p|o]"}
    printResults(text, allOpts, allWords)
}
Task: Long stairs




Go: package main

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

func main() {
    rand.Seed(time.Now().UnixNano())
    totalSecs := 0
    totalSteps := 0
    fmt.Println("Seconds    steps behind    steps ahead")
    fmt.Println("-------    ------------    -----------")
    for trial := 1; trial < 10000; trial++ {
        sbeh := 0
        slen := 100
        secs := 0
        for sbeh < slen {
            sbeh++
            for wiz := 1; wiz < 6; wiz++ {
                if rand.Intn(slen) < sbeh {
                    sbeh++
                }
                slen++
            }
            secs++
            if trial == 1 && secs > 599 && secs < 610 {
                fmt.Printf("%d        %d            %d\n", secs, sbeh, slen-sbeh)
            }
        }
        totalSecs += secs
        totalSteps += slen
    }
    fmt.Println("\nAverage secs taken:", float64(totalSecs)/10000)
    fmt.Println("Average final length of staircase:", float64(totalSteps)/10000)
}
Task: Largest prime factor




Go: package main

import "fmt"

func largestPrimeFactor(n uint64) uint64 {
    if n < 2 {
        return 1
    }
    inc := [8]uint64{4, 2, 4, 2, 4, 6, 2, 6}
    max := uint64(1)
    for n%2 == 0 {
        max = 2
        n /= 2
    }
    for n%3 == 0 {
        max = 3
        n /= 3
    }
    for n%5 == 0 {
        max = 5
        n /= 5
    }
    k := uint64(7)
    i := 0
    for k*k <= n {
        if n%k == 0 {
            max = k
            n /= k
        } else {
            k += inc[i]
            i = (i + 1) % 8
        }
    }
    if n > 1 {
        return n
    }
    return max
}

func main() {
    n := uint64(600851475143)
    fmt.Println("The largest prime factor of", n, "is", largestPrimeFactor(n), "\b.")
}
Task: Getting the number of decimal places




Go: package main

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

var error = "Argument must be a numeric literal or a decimal numeric string."

func getNumDecimals(n interface{}) int {
    switch v := n.(type) {
    case int:
        return 0
    case float64:
        if v == math.Trunc(v) {
            return 0
        }
        s := fmt.Sprintf("%g", v)
        return len(strings.Split(s, ".")[1])
    case string:
        if v == "" {
            log.Fatal(error)
        }
        if v[0] == '+' || v[0] == '-' {
            v = v[1:]
        }
        for _, c := range v {
            if strings.IndexRune("0123456789.", c) == -1 {
                log.Fatal(error)
            }
        }
        s := strings.Split(v, ".")
        ls := len(s)
        if ls == 1 {
            return 0
        } else if ls == 2 {
            return len(s[1])
        } else {
            log.Fatal("Too many decimal points")
        }
    default:
        log.Fatal(error)
    }
    return 0
}

func main() {
    var a = []interface{}{12, 12.345, 12.345555555555, "12.3450", "12.34555555555555555555", 12.345e53}
    for _, n := range a {
        d := getNumDecimals(n)
        switch v := n.(type) {
        case string:
            fmt.Printf("%q has %d decimals\n", v, d)
        case float32, float64:
            fmt.Printf("%g has %d decimals\n", v, d)
        default:
            fmt.Printf("%d has %d decimals\n", v, d)
        }
    }
}
Task: Three word location




Go: package main

import (
    "fmt"
    "strconv"
)

func toWord(w int64) string { return fmt.Sprintf("W%05d", w) }

func fromWord(ws string) int64 {
    var u, _ = strconv.ParseUint(ws[1:], 10, 64)
    return int64(u)
}

func main() {
    fmt.Println("Starting figures:")
    lat := 28.3852
    lon := -81.5638
    fmt.Printf("  latitude = %0.4f, longitude = %0.4f\n", lat, lon)

    
    ilat := int64(lat*10000 + 900000)
    ilon := int64(lon*10000 + 1800000)

    
    latlon := (ilat << 22) + ilon

    
    w1 := (latlon >> 28) & 0x7fff
    w2 := (latlon >> 14) & 0x3fff
    w3 := latlon & 0x3fff

    
    w1s := toWord(w1)
    w2s := toWord(w2)
    w3s := toWord(w3)

    
    fmt.Println("\nThree word location is:")
    fmt.Printf("  %s %s %s\n", w1s, w2s, w3s)

    
    w1 = fromWord(w1s)
    w2 = fromWord(w2s)
    w3 = fromWord(w3s)

    latlon = (w1 << 28) | (w2 << 14) | w3
    ilat = latlon >> 22
    ilon = latlon & 0x3fffff
    lat = float64(ilat-900000) / 10000
    lon = float64(ilon-1800000) / 10000

    
    fmt.Println("\nAfter reversing the procedure:")
    fmt.Printf("  latitude = %0.4f, longitude = %0.4f\n", lat, lon)
}
Task: Vibrating rectangles




Go: package main

import (
    "image"
    "image/color"
    "image/gif"
    "log"
    "os"
)

var (
    black   = color.RGBA{0, 0, 0, 255}
    red     = color.RGBA{255, 0, 0, 255}
    green   = color.RGBA{0, 255, 0, 255}
    blue    = color.RGBA{0, 0, 255, 255}
    magenta = color.RGBA{255, 0, 255, 255}
    cyan    = color.RGBA{0, 255, 255, 255}
    yellow  = color.RGBA{255, 255, 0, 255}
    white   = color.RGBA{255, 255, 255, 255}
)

var palette = []color.Color{red, green, blue, magenta, cyan, yellow, white, black}

func hline(img *image.Paletted, x1, y, x2 int, ci uint8) {
    for ; x1 <= x2; x1++ {
        img.SetColorIndex(x1, y, ci)
    }
}

func vline(img *image.Paletted, x, y1, y2 int, ci uint8) {
    for ; y1 <= y2; y1++ {
        img.SetColorIndex(x, y1, ci)
    }
}

func setBackgroundColor(img *image.Paletted, w, h int, ci uint8) {
    for x := 0; x < w; x++ {
        for y := 0; y < h; y++ {
            img.SetColorIndex(x, y, ci)
        }
    }
}

func drawRectangle(img *image.Paletted, x1, y1, x2, y2 int, ci uint8) {
    hline(img, x1, y1, x2, ci)
    hline(img, x1, y2, x2, ci)
    vline(img, x1, y1, y2, ci)
    vline(img, x2, y1, y2, ci)
}

func main() {
    const nframes = 140
    const delay = 10 
    width, height := 500, 500
    anim := gif.GIF{LoopCount: nframes}
    rect := image.Rect(0, 0, width, height)
    for c := uint8(0); c < 7; c++ {
        for f := 0; f < 20; f++ {
            img := image.NewPaletted(rect, palette)
            setBackgroundColor(img, width, height, 7) 
            for r := 0; r < 20; r++ {
                ix := c
                if r < f {
                    ix = (ix + 1) % 7
                }
                x := width * (r + 1) / 50
                y := height * (r + 1) / 50
                w := width - x
                h := height - y
                drawRectangle(img, x, y, w, h, ix)
            }
            anim.Delay = append(anim.Delay, delay)
            anim.Image = append(anim.Image, img)
        }
    }
    file, err := os.Create("vibrating.gif")
    if err != nil {
        log.Fatal(err)
    }
    defer file.Close() 
    if err2 := gif.EncodeAll(file, &anim); err != nil {
        log.Fatal(err2)
    }   
}
Task: Minimum number of cells after, before, above and below NxN squares




Go: package main

import "fmt"

func printMinCells(n int) {
    fmt.Printf("Minimum number of cells after, before, above and below %d x %d square:\n", n, n)
    p := 1
    if n > 20 {
        p = 2
    }
    for r := 0; r < n; r++ {
        cells := make([]int, n)
        for c := 0; c < n; c++ {
            nums := []int{n - r - 1, r, c, n - c - 1}
            min := n
            for _, num := range nums {
                if num < min {
                    min = num
                }
            }
            cells[c] = min
        }
        fmt.Printf("%*d \n", p, cells)
    }
}

func main() {
    for _, n := range []int{23, 10, 9, 2, 1} {
        printMinCells(n)
        fmt.Println()
    }
}
Task: Maximum difference between adjacent elements of list




Go: package main

import (
    "fmt"
    "math"
)

func main() {
    list := []float64{1, 8, 2, -3, 0, 1, 1, -2.3, 0, 5.5, 8, 6, 2, 9, 11, 10, 3}
    maxDiff := -1.0
    var maxPairs [][2]float64
    for i := 1; i < len(list); i++ {
        diff := math.Abs(list[i-1] - list[i])
        if diff > maxDiff {
            maxDiff = diff
            maxPairs = [][2]float64{{list[i-1], list[i]}}
        } else if diff == maxDiff {
            maxPairs = append(maxPairs, [2]float64{list[i-1], list[i]})
        }
    }
    fmt.Println("The maximum difference between adjacent pairs of the list is:", maxDiff)
    fmt.Println("The pairs with this difference are:", maxPairs)
}
Task: Solve a Hopido puzzle




Go: package main

import (
    "fmt"
    "sort"
)

var board = []string{
    ".00.00.",
    "0000000",
    "0000000",
    ".00000.",
    "..000..",
    "...0...",
}

var moves = [][2]int{
    {-3, 0}, {0, 3}, {3, 0}, {0, -3},
    {2, 2}, {2, -2}, {-2, 2}, {-2, -2},
}

var grid [][]int

var totalToFill = 0

func solve(r, c, count int) bool {
    if count > totalToFill {
        return true
    }
    nbrs := neighbors(r, c)
    if len(nbrs) == 0 && count != totalToFill {
        return false
    }
    sort.Slice(nbrs, func(i, j int) bool {
        return nbrs[i][2] < nbrs[j][2]
    })

    for _, nb := range nbrs {
        r = nb[0]
        c = nb[1]
        grid[r][c] = count
        if solve(r, c, count+1) {
            return true
        }
        grid[r][c] = 0
    }
    return false
}

func neighbors(r, c int) (nbrs [][3]int) {
    for _, m := range moves {
        x := m[0]
        y := m[1]
        if grid[r+y][c+x] == 0 {
            num := countNeighbors(r+y, c+x) - 1
            nbrs = append(nbrs, [3]int{r + y, c + x, num})
        }
    }
    return
}

func countNeighbors(r, c int) int {
    num := 0
    for _, m := range moves {
        if grid[r+m[1]][c+m[0]] == 0 {
            num++
        }
    }
    return num
}

func printResult() {
    for _, row := range grid {
        for _, i := range row {
            if i == -1 {
                fmt.Print("   ")
            } else {
                fmt.Printf("%2d ", i)
            }
        }
        fmt.Println()
    }
}

func main() {
    nRows := len(board) + 6
    nCols := len(board[0]) + 6
    grid = make([][]int, nRows)
    for r := 0; r < nRows; r++ {
        grid[r] = make([]int, nCols)
        for c := 0; c < nCols; c++ {
            grid[r][c] = -1
        }
        for c := 3; c < nCols-3; c++ {
            if r >= 3 && r < nRows-3 {
                if board[r-3][c-3] == '0' {
                    grid[r][c] = 0
                    totalToFill++
                }
            }
        }
    }
    pos, r, c := -1, 0, 0
    for {
        for {
            pos++
            r = pos / nCols
            c = pos % nCols
            if grid[r][c] != -1 {
                break
            }
        }
        grid[r][c] = 1
        if solve(r, c, 2) {
            break
        }
        grid[r][c] = 0
        if pos >= nRows*nCols {
            break
        }
    }
    printResult()
}
Task: Solve a Numbrix puzzle




Go: package main

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

var example1 = []string{
    "00,00,00,00,00,00,00,00,00",
    "00,00,46,45,00,55,74,00,00",
    "00,38,00,00,43,00,00,78,00",
    "00,35,00,00,00,00,00,71,00",
    "00,00,33,00,00,00,59,00,00",
    "00,17,00,00,00,00,00,67,00",
    "00,18,00,00,11,00,00,64,00",
    "00,00,24,21,00,01,02,00,00",
    "00,00,00,00,00,00,00,00,00",
}

var example2 = []string{
    "00,00,00,00,00,00,00,00,00",
    "00,11,12,15,18,21,62,61,00",
    "00,06,00,00,00,00,00,60,00",
    "00,33,00,00,00,00,00,57,00",
    "00,32,00,00,00,00,00,56,00",
    "00,37,00,01,00,00,00,73,00",
    "00,38,00,00,00,00,00,72,00",
    "00,43,44,47,48,51,76,77,00",
    "00,00,00,00,00,00,00,00,00",
}

var moves = [][2]int{{1, 0}, {0, 1}, {-1, 0}, {0, -1}}

var (
    grid        [][]int
    clues       []int
    totalToFill = 0
)

func solve(r, c, count, nextClue int) bool {
    if count > totalToFill {
        return true
    }

    back := grid[r][c]

    if back != 0 && back != count {
        return false
    }

    if back == 0 && nextClue < len(clues) && clues[nextClue] == count {
        return false
    }

    if back == count {
        nextClue++
    }

    grid[r][c] = count
    for _, move := range moves {
        if solve(r+move[1], c+move[0], count+1, nextClue) {
            return true
        }
    }
    grid[r][c] = back
    return false
}

func printResult(n int) {
    fmt.Println("Solution for example", n, "\b:")
    for _, row := range grid {
        for _, i := range row {
            if i == -1 {
                continue
            }
            fmt.Printf("%2d ", i)
        }
        fmt.Println()
    }
}

func main() {
    for n, board := range [2][]string{example1, example2} {
        nRows := len(board) + 2
        nCols := len(strings.Split(board[0], ",")) + 2
        startRow, startCol := 0, 0
        grid = make([][]int, nRows)
        totalToFill = (nRows - 2) * (nCols - 2)
        var lst []int

        for r := 0; r < nRows; r++ {
            grid[r] = make([]int, nCols)
            for c := 0; c < nCols; c++ {
                grid[r][c] = -1
            }
            if r >= 1 && r < nRows-1 {
                row := strings.Split(board[r-1], ",")
                for c := 1; c < nCols-1; c++ {
                    val, _ := strconv.Atoi(row[c-1])
                    if val > 0 {
                        lst = append(lst, val)
                    }
                    if val == 1 {
                        startRow, startCol = r, c
                    }
                    grid[r][c] = val
                }
            }
        }

        sort.Ints(lst)
        clues = lst
        if solve(startRow, startCol, 1, 0) {
            printResult(n + 1)
        }
    }
}
Task: Respond to an unknown method call




Go: package main

import (
    "fmt"
    "reflect"
)

type example struct{}

func (example) Foo() int {
    return 42
}


func (e example) CallMethod(n string) int {
    if m := reflect.ValueOf(e).MethodByName(n); m.IsValid() {
        
        return int(m.Call(nil)[0].Int())
    }
    
    fmt.Println("Unknown method:", n)
    return 0
}

func main() {
    var e example
    fmt.Println(e.CallMethod("Foo"))
    fmt.Println(e.CallMethod("Bar"))
}
Task: Sierpinski curve




Go: package main

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

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

var cx, cy, h float64

func lineTo(newX, newY float64) {
    dc.LineTo(newX-width/2+h, height-newY+2*h)
    cx, cy = newX, newY
}

func lineN() { lineTo(cx, cy-2*h) }
func lineS() { lineTo(cx, cy+2*h) }
func lineE() { lineTo(cx+2*h, cy) }
func lineW() { lineTo(cx-2*h, cy) }

func lineNW() { lineTo(cx-h, cy-h) }
func lineNE() { lineTo(cx+h, cy-h) }
func lineSE() { lineTo(cx+h, cy+h) }
func lineSW() { lineTo(cx-h, cy+h) }

func sierN(level int) {
    if level == 1 {
        lineNE()
        lineN()
        lineNW()
    } else {
        sierN(level - 1)
        lineNE()
        sierE(level - 1)
        lineN()
        sierW(level - 1)
        lineNW()
        sierN(level - 1)
    }
}

func sierE(level int) {
    if level == 1 {
        lineSE()
        lineE()
        lineNE()
    } else {
        sierE(level - 1)
        lineSE()
        sierS(level - 1)
        lineE()
        sierN(level - 1)
        lineNE()
        sierE(level - 1)
    }
}

func sierS(level int) {
    if level == 1 {
        lineSW()
        lineS()
        lineSE()
    } else {
        sierS(level - 1)
        lineSW()
        sierW(level - 1)
        lineS()
        sierE(level - 1)
        lineSE()
        sierS(level - 1)
    }
}

func sierW(level int) {
    if level == 1 {
        lineNW()
        lineW()
        lineSW()
    } else {
        sierW(level - 1)
        lineNW()
        sierN(level - 1)
        lineW()
        sierS(level - 1)
        lineSW()
        sierW(level - 1)
    }
}

func squareCurve(level int) {
    sierN(level)
    lineNE()
    sierE(level)
    lineSE()
    sierS(level)
    lineSW()
    sierW(level)
    lineNW()
    lineNE() 
}

func main() {
    dc.SetRGB(0, 0, 1) 
    dc.Clear()
    level := 5
    cx, cy = width/2, height
    h = cx / math.Pow(2, float64(level+1))
    squareCurve(level)
    dc.SetRGB255(255, 255, 0) 
    dc.SetLineWidth(2)
    dc.Stroke()
    dc.SavePNG("sierpinski_curve.png")
}
Task: Selectively replace multiple instances of a character within a string




Go: package main

import (
    "fmt"
    "strings"
)

func main() {
    s := "abracadabra"
    ss := []byte(s)
    var ixs []int
    for ix, c := range s {
        if c == 'a' {
            ixs = append(ixs, ix)
        }
    }
    repl := "ABaCD"
    for i := 0; i < 5; i++ {
        ss[ixs[i]] = repl[i]
    }
    s = string(ss)
    s = strings.Replace(s, "b", "E", 1)
    s = strings.Replace(s, "r", "F", 2)
    s = strings.Replace(s, "F", "r", 1)
    fmt.Println(s)
}
Task: Joystick position




Go: package main

import (
    "fmt"
    "github.com/nsf/termbox-go"
    "github.com/simulatedsimian/joystick"
    "log"
    "os"
    "strconv"
    "time"
)

func printAt(x, y int, s string) {
    for _, r := range s {
        termbox.SetCell(x, y, r, termbox.ColorDefault, termbox.ColorDefault)
        x++
    }
}

func readJoystick(js joystick.Joystick, hidden bool) {
    jinfo, err := js.Read()
    check(err)

    w, h := termbox.Size()
    tbcd := termbox.ColorDefault
    termbox.Clear(tbcd, tbcd)
    printAt(1, h-1, "q - quit")
    if hidden {
        printAt(11, h-1, "s - show buttons:")
    } else {
        bs := ""
        printAt(11, h-1, "h - hide buttons:")
        for button := 0; button < js.ButtonCount(); button++ {
            if jinfo.Buttons&(1<<uint32(button)) != 0 {
                
                bs += fmt.Sprintf(" %X", button+1)
            }
        }
        printAt(28, h-1, bs)
    }

    
    x := int(float64((jinfo.AxisData[0]+32767)*(w-1)) / 65535)
    y := int(float64((jinfo.AxisData[1]+32767)*(h-2)) / 65535)
    printAt(x, y, "+") 
    termbox.Flush()
}

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

func main() {
    
    
    
    jsid := 0
    
    if len(os.Args) > 1 {
        i, err := strconv.Atoi(os.Args[1])
        check(err)
        jsid = i
    }

    js, jserr := joystick.Open(jsid)
    check(jserr)
 
    err := termbox.Init()
    check(err)
    defer termbox.Close()

    eventQueue := make(chan termbox.Event)
    go func() {
        for {
            eventQueue <- termbox.PollEvent()
        }
    }()

    ticker := time.NewTicker(time.Millisecond * 40)
    hidden := false 

    for doQuit := false; !doQuit; {
        select {
        case ev := <-eventQueue:
            if ev.Type == termbox.EventKey {
                if ev.Ch == 'q' {
                    doQuit = true
                } else if ev.Ch == 'h' {
                    hidden = true
                } else if ev.Ch == 's' {
                    hidden = false
                }
            }
            if ev.Type == termbox.EventResize {
                termbox.Flush()
            }
        case <-ticker.C:
            readJoystick(js, hidden)
        }
    }
}
Task: Nested templated data




Go: package main

import (
    "fmt"
    "os"
    "sort"
    "strings"
    "text/template"
)

func main() {
    const t = `[[[{{index .P 1}}, {{index .P 2}}],
  [{{index .P 3}}, {{index .P 4}}, {{index .P 1}}], 
  {{index .P 5}}]]
`
    type S struct {
        P map[int]string
    }

    var s S
    s.P = map[int]string{
        0: "'Payload#0'", 1: "'Payload#1'", 2: "'Payload#2'", 3: "'Payload#3'",
        4: "'Payload#4'", 5: "'Payload#5'", 6: "'Payload#6'",
    }
    tmpl := template.Must(template.New("").Parse(t))
    tmpl.Execute(os.Stdout, s)

    var unused []int
    for k, _ := range s.P {
        if !strings.Contains(t, fmt.Sprintf("{{index .P %d}}", k)) {
            unused = append(unused, k)
        }
    }
    sort.Ints(unused)
    fmt.Println("\nThe unused payloads have indices of :", unused)
}
Task: Make a backup file




Go: package main

import (
    "fmt"
    "io/ioutil"
    "os"
)

func main() {
    fn := "myth"
    bx := ".backup"
    
    var err error
    if tf, err := os.Readlink(fn); err == nil {
        fn = tf
    }
    
    var fi os.FileInfo
    if fi, err = os.Stat(fn); err != nil {
        fmt.Println(err)
        return
    }
    
    if err = os.Rename(fn, fn+bx); err != nil {
        fmt.Println(err)
        return
    }
    
    err = ioutil.WriteFile(fn, []byte("you too!\n"), fi.Mode().Perm())
    if err != nil {
        fmt.Println(err)
    }
}