JavaScript(ES6),263个字节
n=>(o=(o=[..." ".repeat(n*2)]).map(_=>o.map(_=>s=c=" ")),(g=a=>s++<n&&g(q=[],a.map(p=>o[p[4]][p[3]]==c&&(o[y=p[1]][x=p[0]]=o[y-1][(b=+p[2])?x-1:x+1]="/\\"[b],q.push([x,++y,!b,b?x+1:x-1,y],[b?x-=2:x+=2,y-2,!b,x,y-3])))))([[n,n,1,n,n]]),o.map(r=>r.join``).join`
`)
说明
n=>( // n = desired stage
o= // o = output grid
// [ [ "\\", " " ], [ " ", "\\" ], etc... ]
(o=[..." ".repeat(n*2)]) // create an array the size of the grid
.map(_=>o.map(_=> // loop over it and return the output grid
s= // s = current stage (" " acts the same as 0)
c= // c = blank character
" " // initialise each element to " "
)),
(g= // g = compute stage function
a=> // a = positions to place toothpicks
// [ x, y, isBackslash, checkX, checkY ]
s++<n&& // do nothing if we have reached the desired stage
g(q=[], // q = positions for the next stage's toothpicks
a.map(p=> // p = current potential toothpick position
o[p[4]][p[3]]==c&&( // check the position to make sure it is clear
o[y=p[1]][x=p[0]]= // place bottom toothpick, x/y = position x/y
o[y-1][ // place top toothpick
(b=+p[2]) // b = isBackslash
?x-1:x+1 // top toothpick x depends on direction
]="/\\"[b], // set the location to the appropriate character
// Add the next toothpick positions
q.push([x,++y,!b,b?x+1:x-1,y],
[b?x-=2:x+=2,y-2,!b,x,y-3])
)
)
)
)([[n,n,1,n,n]]), // place the initial toothpicks
o.map(r=>r.join``).join`
` // return the grid converted to a string
)
测试
Stages: <input type="number" oninput='result.innerHTML=(
n=>(o=(o=[..." ".repeat(n*2)]).map(_=>o.map(_=>s=c=" ")),(g=a=>s++<n&&g(q=[],a.map(p=>o[p[4]][p[3]]==c&&(o[y=p[1]][x=p[0]]=o[y-1][(b=+p[2])?x-1:x+1]="/\\"[b],q.push([x,++y,!b,b?x+1:x-1,y],[b?x-=2:x+=2,y-2,!b,x,y-3])))))([[n,n,1,n,n]]),o.map(r=>r.join``).join`
`)
)(+this.value)' /><pre id="result"></pre>