Java 8,159字节
n->{String r="",N="\n",t=r;for(int i=n,j,k;i-->0;t+="+",r+=i>0?N:"")for(j=-n;++j<n;r+=k<n?"+":" ")k=i+(j<0?-j:j);return t+N+r+N+new StringBuffer(r).reverse();}
绝对可以打更多的高尔夫球,但这是一个开始。
说明:
在线尝试。
n->{ // Method with integer parameter and String return-type
String r="", // Result-String, starting empty
N="\n", // Temp-String for new-line to save bytes
t=r; // First-line String, starting empty
for(int i=n,j,k;i-->0 // Loop `i` in the range (n,0]
; // After every iteration:
t+="+", // Append a "+" to the first-line String
r+=i>0?N:"") // Add a new-line if this isn't the last iteration of `i` yet
for(j=-n;++j<n; // Inner loop `j` in the range (-n,n]
r+= // After every iteration, append the result with:
k<n? // If `k` is smaller than the input `n`:
"+" // Append a "+"
: // Else:
" ") // Append a space instead
k=i+(j<0?-j:j); // Set `k` to `i` plus the absolute value of `j`
return t+N // Return the first-line String plus new-line,
+r+N // plus the result-String plus new-line,
+new StringBuffer(r).reverse();}
// plus the result-String again reversed
n
一元吗?