溶けるつららを描く方法


23

彫刻家は、グリーンランドの新しい博物館のつらら彫刻を作成する役割を担っています。彼は2つの数字で構成される上司から仕様を与えられました:[s、m]またはsize and melt。サイズ奇数でなければなりません。彼は本物のつららの写真をいくつか与えられた:

vvvvv [5, 0]
 vvv 
  v


vvvvvvv [7, 0]
 vvvvv 
  vvv
   v


vvvvvvv [7, 2]
 vvvvv 



vvvvvvv [7, 3]




vvv [3, 1]

彼は絵を描くのに役立つプログラムが必要です。許可された言語。プログラムは、受け入れ可能な入力方法であるSとMを取り込む必要があります。次に、そのアスキーアート表現を印刷する必要があります。

Sはv、最初の層にあるsの数です。Mは、下から切り取られるレイヤーの数です。

これはであるため、通常、この競合はバイトベースです。空白は、バイトカウントのためにカウントされます。最小バイトが勝ちます。

編集: [5、3]のように、何も描画しない数字のセットを取得することはありません。ただし、コードを確認する必要はありません


空白はカウントすると言いますが、例ではいくつかの行の末尾にスペースがあります。それは許されますか?
ルイスメンドー

回答:


8

05AB1E、11バイト

;-Ý·¹+'v×.c

;-          Compute x = Input[1]-Input[0]/2  (e.g. 7,2 -> -1.5)
  Ý         Push [0, ..., x]                 (e.g. 7,2 -> [0, -1])
   ·        Multiply each value by 2         (e.g. 7,2 -> [0, -2])
    ¹+      Add Input[0] to each value       (e.g. 7,2 -> [7, 5])
      'v×   String multiply by 'v'
         .c Center all strings and implicitly display them  

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


1
05AB1Eで@Adnanの12バイトを使用してください。
おいしいパスタ

2
@yummypastaよく、私は彼のニックネームは偶然ではないと思う:)
Bacco

ありがとう!アドナンとエミグナは通常、私ができる以上の助けをしてくれます。そして、あなたは正しい、私のニックネームは05AB1Eにかなり関連しています;)。
2016年

16

V、15バイト

Àévò^lYp2x>òÀñd

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

かなり簡単です。

À               " Arg1 times:
 év             "   Insert a 'v'
   ò       ò    " Recursively:
    ^l          "   Break if there is only one character on this line
      Y         "   Yank this line
       p        "   Paste it below us
        2x      "   Delete two characters
          >     "   Indent this line
            À   " Arg2 times:
             ñd "   Delete a line

5
Vは「最も難読化可能な言語」で勝つと思います。
ニッサ

1
その言語はデバッグするのが楽しいようです
BlueWizard

4
ソースコードは、ランダムに生成されたハッシュのように見えます。安全なパスワードとして使用できます。
totymedli

8
この問題を解決できるVという言語があるのが気に入っています。
djechlin

9

05AB1E、12バイト

コード:

ÅÉ'v×R²F¨}.c

説明:

ÅÉ             # List of uneven numbers: [1, 3, 5, ..., input]
  'v×          # String multiply by 'v', giving ['v', 'vvv', 'vvvvv', ...]
     R         # Reverse the array
      ²F }     # Second input times, do...
        ¨      #   Remove the first element of the array
          .c   # Centralize the array

CP-1252エンコードを使用します。オンラインでお試しください!


;-Ý·¹+'v×.c1バイトを節約します
-Osable

@Osableは、まったく別の答えではありませんか?
djechlin

良い点は、両方の答えの背後に大きなアルゴリズムがないため、私は本当に知りません。必要に応じて、別の回答として投稿します。
2016年

1
@Osable Nice find!これとは非常に異なるので、別の答えとして考えてください。
アドナン

7

MATL、22バイト

'v'itQ2/i-wX"R2&PRZ{Zv

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

説明

'v'   % Push character 'v'
it    % Input first number. Duplicate
Q2/   % Add 1 and divide by 2
i-    % Input second number. Subtract
w     % Swap
X"    % Char matrix of 'v' repeated those many times along each dim
R     % Upper triangular part
2&P   % Flip horizontally
R     % Upper triangular part
Z{    % Split char matrix along first dimension into a cell array of strings 
Zv    % Remove trailing spaces from each string. Implicitly display

6

ゼリー、19 バイト

Rm-2”vẋµLḶ⁶ẋżðḣL_¥Y

TryItOnline!

どうやって?

Rm-2”vẋµLḶ⁶ẋżðḣL_¥Y - Main link: s, m
       µ            - monadic chain separation
R                   - range(s)  [1,2,3,...s]
 m-2                - mod -2    [s,s-2,s-4,...,1]
    ”v              - 'v'
      ẋ             - repeat    ['v'*s,...,'vvv','v']  (call this y)
             ð      - dyadic chain separation
        L           - length, effectively (s+1)/2
         Ḷ          - lowered range [0,1,2,...length-1]
          ⁶         - ' '
           ẋ        - repeat ['', ' ', ... ' '*(length-1)]
            ż       - zip with y
                 ¥  - last two links as a dyad
               L    -     length
                _   -     subtract m
              ḣ     - head
                  Y - join with line feeds
                    - implicit print

途中で長さと長さの鎖が好きです;
ETHproductions

ええ、J’(長さが減少した範囲)も同じ効果がありますが、の下位バージョンはなくJLḶちょっとかわいいです:)
ジョナサンアラン

5

バッチ、142バイト

@set/ah=%1-%2-%2
@set s=v
@for /l %%i in (3,2,%1)do @call set s=%%s%%vv
@for /l %%i in (1,2,%h%)do @call echo %%s%%&call set s= %%s:~0,-2%%

5

ルビー、46 44バイト

->s,m{0.upto(s/2-m){|i|puts' '*i+?v*s;s-=2}}

GBのおかげで2バイト節約


puts空白を必要としない
GB

1
そして、あなたはデクリメント秒で1より多くの文字を保存することができます:代わりに?v*(s-2*i)使用?v*s;s-=2
GB

4

Python、76 73バイト

def f(s,m):print"\n".join([' '*(s/2-i/2)+'V'*i for i in range(s,m*2,-2)])

編集: @TuukkaXと@ Challenger5のおかげで3バイト保存されました(ありがとう!)


2
の後にprint、無駄な空白があります:)
Yytsi

1
ラムダを使用しないのはなぜですか?lambda s,m:"\n".join([' '*(s/2-i/2)+'V'*i for i in range(s,m*2,-2)])
0WJYxW9FMN

1
関数コードをの直後に配置してdef f(s,m):、2バイトを節約できます。
エソランジングフルーツ

@ J843136028同じバイト数def f()です。7 lambda は7 です。Challenger5 のヒントでは、defは実際には短くなっています。少なくともそれがあなたが私が思うように意味するものである場合:)
nephi12

@nephiしかし、を削除するprintので、4文字短くなります(lambda s,m:"\n".join(...))。これはlambdasが基本的に暗黙のリターンを持っているためです。
アーティアー

3

JavaScript(ES6)、57バイト

f=(s,m,p=``)=>s<m+m?``:p+`v`.repeat(s)+`
`+f(s-2,m,p+` `)

末尾の改行を出力します。先頭の改行が許容される場合、54バイトの場合:

f=(s,m,p=`
`)=>s<m+m?``:p+`v`.repeat(s)+f(s-2,m,p+` `)

3

Python 2、63バイト

lambda s,m:'\n'.join((s-x)/2*' '+x*'v'for x in range(s,m*2,-2))

3

タートルード、53バ​​イト

@v?,:l[v,l][ [ l]rr[ d,ur]ld' l]?<:d[ [ u]d[ ' d]luu]

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

説明:

@v,           set char var to v, write it to cell

   ?:l        take positive int input, move that many character right, move 1 left

      [v,l]   move left back to the v, writing v on all the cells it goes on

           [                   ]                      until the current cell is a space

             [ l]    move left until finding a space
                 rr  move two right

                   [     ]  until cell is a space
                     d,ur   move down, write v, move up and right


                          ld' l    move left, down, write space

                                [end of big loop]


                                  [that part made the "icicle", the next melts some]




                                ?<:    
           Take integer input again,
           rotate counterclockwise, move that number right (now up the icicle)

                                    d      move down
                                     [               ] until cell is space
                                       [ u]d   up until space is found, down 1
                                            [ ' d]  until space is found, write space to cell and move down
                                                  luu    move left, up, up
                                                   [end loop]

2

Java、138 137バイト

void m(int l,int r){int f=l;do{String v="";for(int i=0;i++<l;v+="v");if(l/2<r)break;System.out.printf("%"+f--+"s%n",v);l-=2;}while(l>0);}

ゴルフをしていない:

void m(int l, int r) {
    int f = l;
    do {
        String v = "";
        for (int i = 0; i++ < l; v += "v");
        if (l / 2 < r) break;
        System.out.printf("%" + f-- + "s%n", v);
        l -= 2;
    } while (l > 0);
}

更新:@ClaytonRamseyのおかげで1バイトとループの本体がなくなりました。


for(int i = 0; i ++ <l; v + = "v");のようにforループを書き換えると、1バイトを削減できます。
クレイトンラムジー

1

C、83バイト

i,j;f(s,m){for(i=-1;i++<s/2-m;)for(j=-1;++j<=s;)putchar(j<s?j>=i&&s-j>i?86:32:10);}

ゴルフをしないと使用法:

i,j;
f(s,m){
  for(i=-1;i++<s/2-m;)
    for(j=-1;++j<=s;)
      putchar(j<s ?
                j>=i&&s-j>i ? 86 : 32
                : 10);
}


main() {

  f(5,0);
  f(7,0);
  f(7,2);
  f(7,3);
  f(3,1);

}

1

Pyth、21バイト

j<E.e+*kd*hyb\v_Uh/Q2

S後にM、改行で区切られた入力を受け取り、結果を出力するプログラム。

テストスイート

使い方

j<E.e+*kd*hyb\v_Uh/Q2  Program. Inputs: Q, E
                  /Q2  Yield Q // 2
                 h      + 1
                U      Yield [0, 1, 2, ..., Q //2 +1]
               _       Reverse
   .e                  Map over with elements as b and zero-indexed indices as k:
           yb           2 * b
          h              + 1
         *   \v          "v" characters
     +                  prepended with
       k                k
      * d                spaces
 <E                    All but the last E elements
j                      Join on newlines
                       Implicitly print
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.