Skip to content

Instantly share code, notes, and snippets.

@toothrot
Created March 18, 2015 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toothrot/459b3cea4b53abd99e18 to your computer and use it in GitHub Desktop.
Save toothrot/459b3cea4b53abd99e18 to your computer and use it in GitHub Desktop.
Exercise: Slices
// https://tour.golang.org/moretypes/14
package main
import "golang.org/x/tour/pic"
func Pic(dx, dy int) [][]uint8 {
mything := make([][]uint8, dy)
for i := 0; i < dy; i++ {
mything[i] = make([]uint8, dx)
}
for i := 0; i < dy; i++ {
for j := 0; j < dx; j++ {
mything[i][j] = uint8((i + j) / 2)
}
}
return mything
}
func main() {
pic.Show(Pic)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment