-
-
Save intel352/3737799 to your computer and use it in GitHub Desktop.
An answer of the exercise: Slices on a tour of Go
This file contains hidden or 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 "code.google.com/p/go-tour/pic" | |
func Pic(dx, dy int) [][]uint8 { | |
x := make([]uint8, dx) | |
y := make([][]uint8, dy) | |
for n := range y { | |
y[n] = x | |
for m := range x { | |
y[n][m] = uint8((n+m)/2) | |
} | |
} | |
return y | |
} | |
func main() { | |
pic.Show(Pic) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's another answer, mainly pasting to show diff approach on the for statement, using range instead of incrementing.