此 ruby 代码生成一个金字塔:
w = 20
1.upto(w) { |i| puts ">"+" "*(w-i)+"."*i*2+" "*(w-i)+"<" }
像这样:
> .. <
> .... <
> ...... <
> ........ <
> .......... <
> ............ <
> .............. <
> ................ <
> .................. <
> .................... <
> ...................... <
> ........................ <
> .......................... <
> ............................ <
> .............................. <
> ................................ <
> .................................. <
> .................................... <
> ...................................... <
>........................................<
我想让金字塔在顶部有一个点而不是两个(目前是因为"."*i*2
使它对称)。
我怎样才能做到这一点?