Skip to content

Instantly share code, notes, and snippets.

@blakesmith
Created July 5, 2012 05:27
Show Gist options
  • Save blakesmith/3051547 to your computer and use it in GitHub Desktop.
Save blakesmith/3051547 to your computer and use it in GitHub Desktop.
Go Tour: Exercise: Exercise: Slices - My solution
package main
import "code.google.com/p/go-tour/pic"
func imageFun(x, y int) uint8 {
return uint8(x) ^ uint8(y)
}
func Pic(dx, dy int) [][]uint8 {
image := make([][]uint8, dx)
for i := 0; i < dx; i++ {
row := make([]uint8, dy)
for j := 0; j < dy; j++ {
row[j] = imageFun(i, j)
}
image[i] = row
}
return image
}
func main() {
pic.Show(Pic)
}
@diegobrunetti
Copy link

diegobrunetti commented Oct 25, 2020

this image := make([][]uint8, dx) should be a slice of length dy, not dx.

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