Go exercises: Slices

Jan 10, 2018 10:11


Originally published at Moishe Beshkin. You can comment here or there.

GoLang tutorial has a task - Create slices for picture

package main import ( "golang.org/x/tour/pic" ) func Pic(dx, dy int) [][]uint8 { result := make([][]uint8,dy) for i:=range result { innerS := make([]uint8, dx) for j := range innerS { switch { case i*j % 15 == 0: innerS[j] = 240 case i/j % 3 == 0: innerS[j] = 120 case i*j % 5 == 0: innerS[j] = 150 default: innerS[j] = 100 } } result[i] = innerS } return result } func main() { pic.Show(Pic) }
here is the result


issues and resolutions

Previous post Next post
Up