Last active
September 14, 2015 16:32
-
-
Save dolmen/1e29ca6f979638e5c24e to your computer and use it in GitHub Desktop.
Learning Go...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Learning Go, following the "Go tour" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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