Skip to content

Instantly share code, notes, and snippets.

@flc
flc / fibonacci_closure.go
Created August 28, 2013 18:01
A Tour of Go - Exercise: Fibonacci closure http://tour.golang.org/#44
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
i, j := 0, 1
return func() int {
ret := i
@flc
flc / loops_and_functions.go
Last active December 21, 2015 21:39
A Tour of Go - Exercise: Loops and Functions http://tour.golang.org/#24
package main
import (
"fmt"
"math"
)
const e = 1e-8 // small delta
@flc
flc / slices.go
Created August 28, 2013 18:40
A Tour of Go - Exercise: Slices http://tour.golang.org/#36
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
img_func := func(x, y int) uint8 {
//return uint8(x*y)
//return uint8((x+y) / 2)
return uint8(x^y)
}
@flc
flc / wordcount.go
Created August 28, 2013 18:50
A Tour of Go - Exercise: Maps http://tour.golang.org/#41
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
words := strings.Fields(s)
ret := make(map[string]int)
@flc
flc / complex_cube_roots.go
Created August 28, 2013 20:20
A Tour of Go - Advanced Exercise: Complex cube roots http://tour.golang.org/#48
package main
import (
"fmt"
"math/cmplx"
)
const e = 1e-10
func Cbrt(x complex128) complex128 {
@flc
flc / errors.go
Created August 28, 2013 21:56
A Tour of Go - Exercise: Errors http://tour.golang.org/#56
package main
import (
"fmt"
"math"
)
type ErrNegativeSqrt float64
@flc
flc / http_handlers.go
Created August 28, 2013 22:19
A Tour of Go - Exercise: HTTP Handlers http://tour.golang.org/#58
package main
import (
"fmt"
"net/http"
)
type String string
@flc
flc / image.go
Created September 4, 2013 14:17
A Tour of Go - Exercise: Images http://tour.golang.org/#60
package main
import (
"code.google.com/p/go-tour/pic"
"image"
"image/color"
)
type Image struct{
@flc
flc / rot13.go
Created September 4, 2013 15:59
A Tour of Go - Exercise: Rot13 Reader http://tour.golang.org/#61
package main
import (
"io"
"os"
"strings"
//"fmt"
"bytes"
)
@flc
flc / btrees_eq.go
Created September 5, 2013 16:07
A Tour of Go - Exercise: Equivalent Binary Trees http://tour.golang.org/#70
package main
import "code.google.com/p/go-tour/tree"
import "fmt"
func _walk(t *tree.Tree, ch chan int) {
if t.Left != nil {
_walk(t.Left, ch)
}