Skip to content

Instantly share code, notes, and snippets.

@dolmen
Last active September 14, 2015 16:32
Show Gist options
  • Save dolmen/1e29ca6f979638e5c24e to your computer and use it in GitHub Desktop.
Save dolmen/1e29ca6f979638e5c24e to your computer and use it in GitHub Desktop.
Learning Go...
Learning Go, following the "Go tour"
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) (z float64) {
z = float64(1)
for w := float64(0); math.Abs(z-w) >= 1e-10; {
fmt.Println(w, z)
w = z
z = z - (z*z - x) / (2*z)
}
return
}
func main() {
fmt.Println(Sqrt(50))
fmt.Println(math.Sqrt(50))
}
package main
import "golang.org/x/tour/pic"
func Pic(dx, dy int) [][]uint8 {
pic := make([][]uint8, dy)
for y := range pic {
pic[y] = make([]uint8, dx)
for x := range pic[y] {
pic[y][x] = uint8((x+y)/2)
}
}
return pic
}
func main() {
pic.Show(Pic)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment