爪哇10,273个 272 268 239字节
n->{var c=new char[++n][n];for(var d:c)java.util.Arrays.fill(d,' ');for(int i=0,j=0,k=0,l=0,r=0,s=0,t=0,u=0;n-->0;){c[i+=r][j+=s]=c[k+=t][l+=u]=42;do{r=t=2;r*=Math.random();t*=Math.random();s=r^1;u=t^1;}while(i+r==k+t&j+s==l+u);}return c;}
在这里在线尝试。
感谢Kevin Cruijssen打高尔夫球29个字节。
非高尔夫版本:
n -> { // lambda taking an int as argument
var c = new char[++n][n]; // the output; increment the virality since the root does not count
for(var d : c) // for every line
java.util.Arrays.fill(d,' '); // initialize it with spaces
for(int i = 0, j = 0, // coordinates of the first branch
k = 0, l = 0, // coordinates of the second branch
r = 0, s = 0, // offsets for the first branch, one will be 0 and the other 1 always except for the first '*' where the two branches overlap
t = 0, u = 0; // offsets for the second branch, one will be 0 and the other 1 always except for the first '*' where the two branches overlap
n-- > 0; ) { // decrement virality and repeat as many times
c[i+=r][j+=s] = c[k+=t][l+=u] = 42; // move according to offsets and place an '*' for each branch, 42 is ASCII code
do { // randomly pick offsets for both branches
r = t = 2; // Math.random() provides results in [0,1)
r *= Math.random(); // flip a coin for the first branch
t *= Math.random(); // flip another coin for the second
s = r^1; // set s to 0 if r=1, to 1 if r=0
u = t^1; // set u to 0 if t=1, to 1 if t=0
} while(i+r==k+t&j+s==l+u); // repeat if the branches overlap
}
return c; // return the output
}