Last active
April 17, 2020 20:41
-
-
Save krry/34d84a617f0711722b7b601617d077fa to your computer and use it in GitHub Desktop.
An answer to the Slices exercise in A Tour of Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "golang.org/x/tour/pic" | |
func Pic(dx, dy int) [][]uint8 { | |
grid := make([][]uint8, dy) | |
for y := range grid { | |
line := make([]uint8, dx) | |
for x := range line { | |
line[x] = uint8(y-x) | |
} | |
grid[y] = line | |
// why doesn't this work instead? | |
// grid = append(grid, line) | |
} | |
return grid | |
} | |
func main() { | |
pic.Show(Pic) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Righto, @ibdimitrov. Thanks for the heads up.