Skip to content

Instantly share code, notes, and snippets.

@khajer
Created June 5, 2018 09:24
Show Gist options
  • Select an option

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

Select an option

Save khajer/5a9688d19cb86eba72687fe0388aef3c to your computer and use it in GitHub Desktop.
/*
*
***
*****
*******
*********
***********
*********
*******
*****
***
*
*/
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; i++ {
n := level - i
s := (i*2)+1
txt += replaceStr(ch, n)+replaceStr(star, s)
txt += "\n"
}
for i:=level;i>=0 ; i-- {
n := level - i
s := (i*2)+1
txt += replaceStr(ch, n)+ replaceStr(star, s)
txt += "\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