Skip to content

Instantly share code, notes, and snippets.

@rajaravivarma-r
Created November 3, 2023 10:33
Show Gist options
  • Select an option

  • Save rajaravivarma-r/d55eb797d8b267adfbf703a748f833cc to your computer and use it in GitHub Desktop.

Select an option

Save rajaravivarma-r/d55eb797d8b267adfbf703a748f833cc to your computer and use it in GitHub Desktop.
Implement Pic. It should return a slice of length dy, each element of which is a slice of dx 8-bit unsigned integers.
package main
import "golang.org/x/tour/pic"
func Pic(dx, dy int) [][]uint8 {
a := make([][]uint8, dy)
for i := range a {
a[i] = make([]uint8, dx)
}
for i := 0; i < dy; i++ {
for k := 0; k < dx; k++ {
if i % 2 == 0 {
a[i][k] = uint8((i + k) / 2)
} else {
a[i][k] = uint8(i^k)
}
}
}
return a
}
func main() {
pic.Show(Pic)
}
@rajaravivarma-r
Copy link
Author

Output: slices-pic

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