Ruby, 14191
f=->n{q="a=["/\\"
a=[q].center(2*n)]
2.upto(n-1).times{a<<a[-1].gsub(/\\\/| ?(\/) ?|," ?(\\) ?/"){|x|{"\\.gsub(/"=>" ",?\\=>q,?\/=>q}[x.tr("|\\ "/,"""/\\")]}}
a.map{|x|x.center 2*n}*"\n"a*"\n"}
Explanation
- Input is taken as an argument to a lambda. It is expected to be an
Integer
.
- Using string replacement basedUse
String#center
to create a String
"/\"
with n - 2
spaces on rules 1each side and 2 in the problemput it into an Array
is constructed(a
).
- The elements inAdd to
a
the Array are centered usinglast element of String#centera
with every occurrence of "\/"
replaced with " "
and joined together usingevery occurrence of " /"
or " \"
replaced with "/\"
.
- Use
Array#*
to join a
into a String
separated by "\n"
.