ASCII星をいくつか描く


15

入力として腕のサイズを指定して、ASCIIスターを描くプログラムまたは関数を作成します。

ここにサイズの星があります 1

_/\_
\  /
|/\|

ここにサイズの星があります 2

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

ここにサイズの星があります 3

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

等々。

入力

単一の正の整数、任意の便利な形式でn > 0

出力

上記の規則に従う星のASCIIアート表現。ポイントが適切に整列している場合、先頭または末尾の改行またはその他の空白はオプションです。

ルール

  • 完全なプログラムまたは機能のいずれかが受け入れられます。関数の場合、出力する代わりに出力を返すことができます。
  • 標準的な抜け穴は禁止されています。
  • これはので、通常のゴルフルールがすべて適用され、最短のコード(バイト単位)が勝ちます。

6
それはちょうど私の画面ですか、または星は異常に高くて薄く見えますか?
caird coinheringaahing

2
愚かなASCIIと浅い斜面の欠如...
totallyhuman

@cairdcoinheringaahing SEで使用されるフォントは正方形ではありません-行間に大きな空白があり、歪みが大きくなります。
AdmBorkBork

回答:


12

20 17バイト

ニールのおかげで-3バイト。

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をもらったら…ありがとうございます!
完全に人間

十分に近い。私は実際に持っていたMove(:Right); for (n) Print("_");
ニール

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

4

パイソン2 166の160 157 155  152バイト

execアプローチはまったく同じバイト数です。

i=input();t,z=" \\";y=t*2
for k in range(i*3):s=k%i;o=i+~s;p=i+o;g="_ "[i>k+1]*p;print[g+"/"+y*k+z+g,t*s+z+y*p+"/",~-i*t+"|"+o*t+"/"+y*s+z+o*t+"|"][k/i]

オンラインでお試しください!

Jonathan Frechのおかげで3バイト節約できました。


あなたは、交換することにより、いくつかのバイトを節約できるt=" ";y,z=t*2,"\\"t,z=" \\";y=t+t
ジョナサンフレッチ

@JonathanFrechありがとうございます。
ミスターXcoder

3

Java 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

そして、あなたが移動することで、他の2つのバイトをまだ保存することができますint o=あまりにも外に(ループを268バイト
ミスターXcoder

for-loopブラケットを++削除し、の最後の出現で直接使用することによりi、さらに4バイト節約できます:264 bytes
ケビンCruijssen


@Nevay非常に賢い、ありがとう
ロベルトグラハム

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行目は、±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バイト

解決策はmethod 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に感謝


弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.