Created
April 18, 2015 10:53
-
-
Save iporsut/35457da95a4181d840dc to your computer and use it in GitHub Desktop.
Go Diamond
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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