summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-11-11 09:57:45 +0100
committerDimitri Sokolyuk <demon@dim13.org>2016-11-11 09:57:45 +0100
commit5692e2217c6074504884ad2b3c64d555452cc7f2 (patch)
tree297f2f9bdce00892c90ab7ba306fe7be4d563c11
parent370ee0d3807ff75b0584a23eb3025e08fc35e154 (diff)
Solve diamond
-rw-r--r--go/diamond/diamond.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/go/diamond/diamond.go b/go/diamond/diamond.go
new file mode 100644
index 0000000..37e74fd
--- /dev/null
+++ b/go/diamond/diamond.go
@@ -0,0 +1,24 @@
+package diamond
+
+import (
+ "bytes"
+ "errors"
+)
+
+const testVersion = 1
+
+func Gen(b byte) (string, error) {
+ if b < 'A' || b > 'Z' {
+ return "", errors.New("out of range")
+ }
+ x := int(b - 'A')
+ rows := make([][]byte, 2*x+1)
+ for i, j := x, 0; i >= 0; i, j = i-1, j+1 {
+ line := bytes.Repeat([]byte{' '}, 2*x+2)
+ line[2*x+1] = '\n'
+ char := 'A' + byte(j)
+ line[i], line[2*x-i] = char, char
+ rows[j], rows[2*x-j] = line, line
+ }
+ return string(bytes.Join(rows, nil)), nil
+}