画一些ASCII星


15

给定臂的大小作为输入,编写一个绘制ASCII星号的程序或函数。

这是一颗大小的星星 1

_/\_
\  /
|/\|

这是一颗大小的星星 2

   /\
__/  \__
\      /
 \    /
 | /\ |
 |/  \|

这是一颗大小的星星 3

     /\
    /  \
___/    \___
\          /
 \        /
  \      /
  |  /\  |
  | /  \ |
  |/    \|

等等。

输入值

任何方便格式的一个正整数,n > 0

输出量

遵循上述规则,以ASCII艺术形式表示星星。前导/尾随换行符或其他空格是可选的,但前提是要正确对齐这些点。

规则

  • 完整的程序或功能都是可以接受的。如果是函数,则可以返回输出而不是打印输出。
  • 禁止出现标准漏洞
  • 这是因此所有常见的高​​尔夫规则都适用,并且最短的代码(以字节为单位)获胜。

6
只是我的屏幕,还是星星看起来异常高大而稀疏?
caird coinheringaahing

2
愚蠢的ASCII码及其缺乏浅
斜率的信息

@cairdcoinheringaahing SE使用的字体不是方形的-行之间有很大的空白,这会增加失真。
AdmBorkBork

Answers:


12

木炭20 17字节

-3个字节,感谢Neil。

Nν↙ν↑↑ν↖ν ×_ν↗ν‖M

在线尝试!链接是详细版本。

我对这个高尔夫很满意,所以...

说明

Nν                 take a number as input and store in ν
  ↙ν               print / ν times downwards to the left
    ↑              move up once
     ↑ν            print | ν times upwards
       ↖ν          print \ ν times upwards to the left
                   print a space
          ×_ν      print _ ν times
             ↗ν    print / ν times upwards to the right
               ‖M  reflect horizontally
     /\                           
    /  \    "No, this is Patrick!"
___/    \___                      
\   ☉ ☉    /                      
 \   𝐷    /                       
  \      /                        
  |  /\  |                        
  | /  \ |                        
  |/    \| 

从下到上绘制可节省2个字节。
尼尔


那是因为Polygon将光标留在最后一个字符上,但是我没有使用Polygon...实际上我也没有使用最好的代码,我现在降至17。
尼尔

我不知道我是否能像您一样获得17分,但是...谢谢!
–totalhuman

足够近了。我居然有Move(:Right); for (n) Print("_");
尼尔于2009年

5

SOGL V0.1227 24 个字节

╔*¹.╚№┼№.╝+ø┐.∙.1ž.╚┼+╬³

在这里尝试!

说明:

╔*                        push a string with input amount of underscores
  ¹                       wrap that in an array
   .╚                     push a "/" diagonal of the size of the input (the top lines)
     №                    reverse vertically
      ┼                   add horizontally the underscores behind the array
       №                  reverse vertically back
        .╝+               below that add a "\" diagonal (middle lines)
           ø              push an empty string as the base of the vertical bars
            ┐.∙           get an array of "|" with the length of the input
               .1ž        at [input; 1] in the empty string insert that
                  .╚┼     horizontally append a "/" diagonal
                     +    add that below everything else
                      ╬³  palindromize horizontally


3

爪哇8,385 376 344 304 285 280 268 264 252 250 + 19个字节

n-> {int s = 2 * n,w = 2 * s,e = n-1,i = 0,o,l [] [] = new int [n * 3] [w]; for(; i <n; l [i] [s +〜i] = l [n + i] [w +〜i] = l [o] [s +〜i] = 47,l [i] [o] = l [o] [ o] = l [n + i] [i] = 92,l [e] [i] = l [e] [w-++ i] = 95,l [o] [e] = l [o] [ s + n] = 124)o = s + i; for(int [] b:l)System.out.println(new String(b,0,w).replace(“ ”,“”));}

在线尝试!


您可以使用按位技巧将其缩短10个字节,并将所有整数声明移出循环(270个字节
Xcoder先生17年

您也可以通过将int o=循环移到外部来节省另外2个字节(268个字节
Xcoder先生17年

您可以省去for循环括号,++直接在最后一次出现的情况下使用i,再节省4个字节,例如264个字节
凯文·克鲁伊森


@Nevay非常聪明,谢谢
Roberto Graham

2

Mathematica,189个字节

n(
  s_±x_±y_:=s->Array[If[x==y,s," "]&,{n,n}];
  StringRiffle[Characters@{"_/\\_","\\  /","|/\\:"}/.
    {"_"±#±n,"|"±#2±n,":"±#2±1,"\\"±#±#2,"/"±(n-#+1)±#2," "±0±1}
    /.":"->"|"//ArrayFlatten,"
",""])

第2行定义了helper运算符±,用于使第4行求值为:

{"_"  -> Array[If[#1 == n,          "_", " "] &, {n, n}], 
 "|"  -> Array[If[#2 == n,          "|", " "] &, {n, n}], 
 ":"  -> Array[If[#2 == 1,          ":", " "] &, {n, n}], 
 "\\" -> Array[If[#1 == #2,         "\\"," "] &, {n, n}], 
 "/"  -> Array[If[1 + n - #1 == #2, "/", " "] &, {n, n}], 
 " "  -> Array[If[0 == 1,           " ", " "] &, {n, n}]}

在第3行中,ReplaceAll/.)代表一个代表大小为1的恒星的矩阵,以及上述规则的列表。对于最后的步骤,我们使用ArrayFlatten,比SubstitutionSystemStringRiffle


2

Java 7,295字节

解决方法f

String s(String s,int n){while(n-->0)s=" "+s;return s;}String f(int x){String n="\n",s="/",b="\\",o="",u="_";int i=0;for(x--;i<x;u+="_")o+=s(s,2*x-i+1)+s(b,2*i++)+n;o+=u+s+s(b,2*i)+u+n;while(i>=0)o+=s(b,x-i)+s(s,4*x-2*(x+~i--))+n;while(i++<x)o+=s("|",x)+s(s,x-i)+s(b,2*i)+s("|",x-i)+n;return o;}

在线试用(JDK 8)

不打高尔夫球

String s(String s, int n) {
    while (n-- > 0)
        s = " " + s;
    return s;
}

String f(int x) {
    String
        n = "\n",
        s = "/",
        b = "\\",
        o = "",
        u = "_"
    ;
    int i = 0;
    for (x--; i < x; u += "_")
        o += s(s, 2*x - i + 1) + s(b, 2 * i++) + n;
    o += u + s + s(b, 2 * i) + u + n;
    while (i >= 0)
        o += s(b, x - i) + s(s, 4*x - 2*(x + ~i--)) + n;
    while (i++ < x)
        o += s("|", x) + s(s, x - i) + s(b, 2 * i) + s("|", x - i) + n;
    return o;
}

致谢

  • -1字节感谢Kevin Cruijssen


0

Python 2,137字节

n=input()
b,f,s,v='\/ |'
for i in range(3*n):u=i/~-n*n*'_';d=f+i%n*2*s+b;print[u+d+u,b+s*2*(3*n+~i)+f,v+d.center(2*n)+v][i/n].center(4*n)

在线尝试!

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.