Skip to content

Instantly share code, notes, and snippets.

@uraimo
Last active December 17, 2015 23:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uraimo/5693198 to your computer and use it in GitHub Desktop.
Save uraimo/5693198 to your computer and use it in GitHub Desktop.
A Tour of Go: Slices exercise answer , added a factorial for a better picture
package main
import "code.google.com/p/go-tour/pic"
func Fact(x uint8) uint8 {
if x>1 {
return x * (x-1)
}
return x+1
}
func Pic(dx, dy int) [][]uint8 {
res := make([][]uint8,dy,dy)
for y:= range res {
res[y] = make([]uint8,dx,dx)
for x := range res[y] {
res[y][x] = uint8(x)*Fact(uint8(y))
}
}
return res
}
func main() {
pic.Show(Pic)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment