I have no Go pun this time. Sorry, I need coffee for that.
pyramid.go
packagepyramid// Pyramid creates a text pyramid of the given heightfuncPyramid(heightint)string{ifheight<=0{return""}// Determine width of pyramid basewidth:=(height*2)-1// Get middle of pyramidmiddle:=int(width/2)row:=0// Initialize a base row with only spacesbase:=make([]rune,width,width)fori:=rangebase{base[i]=' '}// Set the top row 'block'base[middle]='*'varpyramidstring// Build the pyramid starting from the topforrow<height{base[middle+row]='*'base[middle-row]='*'pyramid+=string(base)+"\n"row++}returnpyramid}
I have no Go pun this time. Sorry, I need coffee for that.
pyramid.go
pyramid_test.go