Skip to content

Instantly share code, notes, and snippets.

@intel352
Forked from tetsuok/answer_pic.go
Created September 17, 2012 14:45
Show Gist options
  • Save intel352/3737799 to your computer and use it in GitHub Desktop.
Save intel352/3737799 to your computer and use it in GitHub Desktop.
An answer of the exercise: Slices on a tour of Go
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)
}
@intel352
Copy link
Author

Here's another answer, mainly pasting to show diff approach on the for statement, using range instead of incrementing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment