编写一个接受正整数N的程序或函数,打印或返回N×padding艺术字符串,其上半部分是由('s组成的半圆,下半部是由V's组成的向下三角形,空格用作填充。
换句话说,制作一个ASCII冰淇淋筒:(N=17输出)
(((((
(((((((((
(((((((((((((
(((((((((((((
(((((((((((((((
(((((((((((((((
(((((((((((((((((
(((((((((((((((((
VVVVVVVVVVVVVVVVV
VVVVVVVVVVVVVVV
VVVVVVVVVVVVV
VVVVVVVVVVV
VVVVVVVVV
VVVVVVV
VVVVV
VVV
V 下面是N=1到5的输出。注意,对于奇数N,三角形总是较大的一半。
V
((
VV
(((
VVV
V
((
((((
VVVV
VV
(((
(((((
VVVVV
VVV
V 这是一个N= 101的巴斯特宾.
下面是一个未使用的Python 3引用实现:
N = int(input())
ic = [[' '] * N for _ in range(N)]
for y in range(N//2):
for x in range(N):
if (x - (N - 1) / 2)**2 + (y - (N - 1) / 2)**2 < (N / 2)**2:
ic[y][x] = '('
for y in range(N//2, N):
for x in range(y - N//2, N - (y - N//2)):
ic[y][x] = 'V'
for line in ic:
print(''.join(line))(、V和空格。最短的提交单位字节获胜。平局是最古老的投稿。
发布于 2015-03-02 21:54:47
在网上试试。
{:Z{Z{Z(2./:R-zYR<):P#YR-zP#+Z2./P#>SP?}/N}fY}我认为这目前完全模仿了最初的规范,这是我开始生成这个答案时所需要的。可能会通过使数学不太精确到原始规范来节省几个字节,但是在我找到一种方法来保存超过一个或两个字节之前,我将保持原样。
{ "Begin block";
:Z{ "For each y from 0 to input-1";
Z{ "For each x from 0 to input-1";
Z(2./:R "Calculate the radius as (input-1)/2.0";
-z "Calculate the horizontal distance from the center";
YR<):P "Calculate the power to raise distances to: (y<radius)+1
(This results in Euclidean distance being calculated for
the ice cream and Manhattan distance being calculated
for the cone)";
# "Raise the horizontal distance to the determined power";
YR-zP# "Calculate the vertical distance from the center and
raise it to the determined power";
+ "Add the horizontal and vertical distances";
Z2./P# "Calculate the solid distance threshold and raise it to
the determined power";
>SP? "If the solid threshold is exceeded, produce a space;
otherwise, produce the determined power digit
(This results in ice cream being represented by the
digit '2' and the cone by the digit '1')";
}/ "End x loop";
N "Produce a new line";
}fY "End y loop";
} "End block";https://codegolf.stackexchange.com/questions/47255
复制相似问题