Skip to content

Instantly share code, notes, and snippets.

@khajer
Created June 5, 2018 10:01
Show Gist options
  • Select an option

  • Save khajer/cfb08c56b5bc39b9a0fe9369ccb8fd5f to your computer and use it in GitHub Desktop.

Select an option

Save khajer/cfb08c56b5bc39b9a0fe9369ccb8fd5f to your computer and use it in GitHub Desktop.
gen star
/*
*
***
*****
*******
*********
***********
*********
*******
*****
***
*
*/
package main
import (
"fmt"
)
func replaceStr(ch string, n int) string{
txt := ""
for i:=0; i<n;i++{txt+=ch}
return txt
}
func genLevel(level int) string{
txt := ""
ch := " "
star := "*"
for i:=0; i< (level*2)+1; i++{
if i < level{
txt += replaceStr(ch, level - i)+replaceStr(star, (i*2)+1) +"\n"
}else{
txt += replaceStr(ch, i-level)+replaceStr(star, (level*2)-((i-level)*2) +1) +"\n"
}
}
return txt
}
func main() {
fmt.Println(genLevel(5))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment