Skip to content

Instantly share code, notes, and snippets.

@iporsut
Created April 18, 2015 10:53
Show Gist options
  • Save iporsut/35457da95a4181d840dc to your computer and use it in GitHub Desktop.
Save iporsut/35457da95a4181d840dc to your computer and use it in GitHub Desktop.
Go Diamond
package main
import "fmt"
func space(ch rune, end rune) (side int, in int) {
if ch == 'A' {
in = 0
} else {
in = int((ch-'A')*2 - 1)
}
side = int(end - ch)
return
}
func main() {
var ch rune
fmt.Print("Enter Letter : ")
fmt.Scanf("%c", &ch)
for s := 'A'; s <= ch; s++ {
sidesp, insp := space(s, ch)
for i := 1; i <= sidesp; i++ {
fmt.Print(" ")
}
fmt.Printf("%c", s)
if insp == 0 {
fmt.Println()
continue
}
for i := 1; i <= insp; i++ {
fmt.Print(" ")
}
fmt.Printf("%c\n", s)
}
for s := ch - 1; s >= 'A'; s-- {
sidesp, insp := space(s, ch)
for i := 1; i <= sidesp; i++ {
fmt.Print(" ")
}
fmt.Printf("%c", s)
if insp == 0 {
fmt.Println()
continue
}
for i := 1; i <= insp; i++ {
fmt.Print(" ")
}
fmt.Printf("%c\n", s)
}
fmt.Scanln()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment