Skip to content

Instantly share code, notes, and snippets.

@shiwork
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save shiwork/0287e107d20d0e2822a3 to your computer and use it in GitHub Desktop.

Select an option

Save shiwork/0287e107d20d0e2822a3 to your computer and use it in GitHub Desktop.
A Tour of go
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
wc := make(map[string]int)
for _, ss := range strings.Fields(s) {
wc[ss]++
}
return wc
}
func main() {
wc.Test(WordCount)
}
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
fi, fj := 0, 1
return func() int {
fi, fj = fj, fi+fj
return fj
}
}
func main() {
f := fibonacci()
for i := 0; i < 10; i++ {
fmt.Println(f())
}
}
package main
import (
"fmt"
)
func Cbrt(x complex128) complex128 {
z := complex128(1)
for i:=0; i<100000; i++{
z = z-(z*z*z-x)/(3*z*z)
}
return z
}
func main() {
fmt.Println(Cbrt(2))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment