37 lines
693 B
Go
37 lines
693 B
Go
|
package diamond
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
const testVersion = 1
|
||
|
|
||
|
func Gen(c byte) (string, error) {
|
||
|
if c > 'Z' || c < 'A' {
|
||
|
return "", errors.New("Out of Range")
|
||
|
}
|
||
|
d := rune(strings.ToUpper(string(c))[0])
|
||
|
|
||
|
var ret string
|
||
|
for i := 'A'; i <= d; i++ {
|
||
|
ret += PrintRow(i, d) + "\n"
|
||
|
}
|
||
|
for i := d - 1; i >= 'A'; i-- {
|
||
|
ret += PrintRow(i, d) + "\n"
|
||
|
}
|
||
|
return ret, nil
|
||
|
}
|
||
|
|
||
|
func PrintRow(rowChar rune, genChar rune) string {
|
||
|
var ret string
|
||
|
ret += strings.Repeat(" ", int(genChar-rowChar))
|
||
|
ret += string(rowChar)
|
||
|
if rowChar > 'A' {
|
||
|
ret += strings.Repeat(" ", (2*int(rowChar-'A') - 1))
|
||
|
ret += string(rowChar)
|
||
|
}
|
||
|
ret += strings.Repeat(" ", int(genChar-rowChar))
|
||
|
return ret
|
||
|
}
|