ルビー、111 99 77 73 68 64 57 56バイト
Benjamin Urquhartに -12バイト、manatworkに-43 バイト、Value Inkに -2バイト。
->i{s=[];puts (0...i).map{|j|s=(p=' '*j)+?/,*s;p+?\\},s}
オンラインでお試しください!
説明:
f=->i{ # instead of a function, use a lambda
s=[] # needs a helper variable *now*, for scope
puts( # puts takes arbitrary num of args; \n after each
(0...i).map{|j| # not from 0 to i but from 0 to i-1 (*three* dots)
s=(
p=' '*j # p will remain in scope inside of .map,
)
+?/ # character literal instead of string
,*s # essentially appending to the array
p+?\\ # p is what's returned by .map, not s!
}, # up until here, 1st arg to display
s # NOW, as the *2nd* arg, s is displayed
)
}
代替(ただしより長い)ソリューション
友人がこの答えを読んでから、さらに2、3のアプローチを考え出そうとしました。広大なインターウェブに負けないように、ここにも配置します。
挿入およびシフト解除、72バイト
->n{puts (0...n).inject([]){|s,i|i=' '*(n-1-i);s.unshift i+?\\;s<<i+?/}}
オンラインでお試しください!
downto、注入およびシフト解除、80バイト
->n{puts n.downto(1).map{|i|' '*(i-1)}.inject([]){|s,i|s<<i+?/;s.unshift i+?\\}}
オンラインでお試しください!
興味深い、2つの非ネストループ、127バイト
->n{
r=->s,c{s[0..-(c+1)],s[-c..-1]=s[c..-1],s[0..c-1];s};
n.times{|i|puts r[' '*n+?\\,n-i]}
n.times{|i|puts r[' '*n+?/,i+1]}
}
オンラインでお試しください!