如何绘制融化的冰柱


23

雕塑家的任务是为格陵兰新博物馆创建冰柱雕塑。老板已给他指定了规格,该规格由两个数字组成:[s,m]或尺寸和熔体。大小必须为奇数。他得到了一些冰柱的照片:

vvvvv [5, 0]
 vvv 
  v


vvvvvvv [7, 0]
 vvvvv 
  vvv
   v


vvvvvvv [7, 2]
 vvvvv 



vvvvvvv [7, 3]




vvv [3, 1]

他需要一个帮助画画的程序。允许使用任何语言。程序需要接受S和M,任何可接受的输入方法。然后,您必须打印出它的ascii艺术表示。

S是v第一层上有多少个。M是从底部切出多少层。

这是,因此通常情况下,此比赛是基于字节的。空白不计入字节计数。最少字节获胜。

编辑: 您将永远不会获得不画任何数字的一组数字,例如[5,3]。检查代码但是需要。


您说空格确实很重要,但是在示例中某些行的末尾有空格。可以吗
路易斯·门多

Answers:


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个字节!
yummypasta

2
@yummypasta好吧,我认为他的昵称不是巧合:)
Bacco

谢谢!通常,阿德南(Adnan)和艾米娜(Emigna)对我的帮助超过了当时的帮助。您是对的,我的昵称与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
该语言调试
起来

4
源代码看起来像一些随机生成的哈希。我可以将其用作安全密码。
totymedli '16

8
我喜欢有一种叫做V的语言可以解决这个问题。
djechlin '16

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×.c会节省一个字节
2016年

@Osable不仅仅是一个完全不同的答案吗?
djechlin '16

好点,我真的不知道,因为两个答案后面都没有大的算法。如果需要,我将其发布为另一个答案。
2016年

1
@Osable尼斯找到!我认为您应该将其作为不同的答案,因为它与这个答案有很大的不同。
阿德南

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’(长度减小的范围)也将具有相同的效果,但是没有降低的版本J,并且LḶ有点可爱:)
Jonathan Allan

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

Ruby,46个 44字节

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

借助GB,节省了2个字节


puts不需要空格
GB

1
而且您可以通过减少s来保存一个字符:代替?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,有一个无用的空白:)
Yttsi '16

1
为什么不使用lambda?lambda s,m:"\n".join([' '*(s/2-i/2)+'V'*i for i in range(s,m*2,-2)])
0WJYxW9FMN16年

1
您可以将功能代码直接放在后面def f(s,m):,节省两个字节。
硕果累累

@ J843136028字节数相同:def f()7 lambda 是7。使用Challenger5的技巧,def实际上更短。至少如果那是你的意思,就像我想的那样:)
nephi12

@nephi但是您也要删除print,因此它(lambda s,m:"\n".join(...))短了4个字符,因为lambdas基本具有隐式返回。
Artyer

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

Turtlèd,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,一个字节和循环主体消失了。


如果将for循环重写为for(int i = 0; i ++ <l; v + =“ v”);,则可以减少一个字节。
克莱顿·拉姆齐

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
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.