23
\$\begingroup\$

A sculptor is tasked to creating icicle sculptures for the new museum in Greenland. He has been given specifications by his boss, which consists of two numbers: [s, m] or size and melt. Size must be an odd number. He was given some photos of real icicles:

vvvvv [5, 0]
 vvv 
  v


vvvvvvv [7, 0]
 vvvvv 
  vvv
   v


vvvvvvv [7, 2]
 vvvvv 



vvvvvvv [7, 3]




vvv [3, 1]

He needs a program to help draw. Any language allowed. The program needs to take in S and M, any method of input acceptable. You must then print out an ascii art representation of it.

S is how many vs are on the first layer. M is how many layers are cut out from the bottom.

This is , so as usual this competition is byte based. White space does count for byte counting. Least bytes wins.

Edit: You will never get a set of numbers that draws nothing, for example [5, 3]. Checking code is not required however.

\$\endgroup\$
1
  • \$\begingroup\$ You say whitespace does count, but in the examples some lines have trailing spaces. Is that allowed? \$\endgroup\$
    – Luis Mendo
    Nov 25, 2016 at 10:09

14 Answers 14

16
\$\begingroup\$

V, 15 bytes

Àévò^lYp2x>òÀñd

Try it online!

Fairly straightforward.

À               " 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
\$\endgroup\$
4
  • 5
    \$\begingroup\$ I think that V wins for "most obfuscatable language". \$\endgroup\$
    – Nissa
    Nov 25, 2016 at 2:54
  • 1
    \$\begingroup\$ that language looks fun to debug \$\endgroup\$
    – BlueWizard
    Nov 25, 2016 at 10:46
  • 4
    \$\begingroup\$ The source code looks like some random generated hash. I could use it as a safe password. \$\endgroup\$
    – totymedli
    Nov 25, 2016 at 21:51
  • 8
    \$\begingroup\$ I like that there's a language called V that can solve this problem. \$\endgroup\$
    – djechlin
    Nov 26, 2016 at 1:18
9
\$\begingroup\$

05AB1E, 12 bytes

Code:

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

Explanation:

ÅÉ             # 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

Uses the CP-1252 encoding. Try it online!

\$\endgroup\$
4
  • \$\begingroup\$ ;-Ý·¹+'v×.c would save one byte \$\endgroup\$
    – Osable
    Nov 25, 2016 at 17:19
  • \$\begingroup\$ @Osable isn't that just a completely different answer? \$\endgroup\$
    – djechlin
    Nov 26, 2016 at 1:18
  • \$\begingroup\$ Good point, I really don't know since there is no big algorithm behind both answers. I'll post it as another answer if needed. \$\endgroup\$
    – Osable
    Nov 26, 2016 at 9:45
  • 1
    \$\begingroup\$ @Osable Nice find! I think you should put it as a different answer, since it's very different from this one. \$\endgroup\$
    – Adnan
    Nov 26, 2016 at 9:49
8
\$\begingroup\$

05AB1E, 11 bytes

;-Ý·¹+'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  

Try it online!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Good Job, you bean @Adnan's 12 bytes in 05AB1E!! \$\endgroup\$
    – yummypasta
    Nov 26, 2016 at 16:12
  • 2
    \$\begingroup\$ @yummypasta well, I think his nick is not a coincidence :) \$\endgroup\$
    – Bacco
    Nov 27, 2016 at 2:28
  • \$\begingroup\$ Thanks! Adnan and Emigna usually help me more than I can help then. And you're right, my nickname is quite related to 05AB1E ;) . \$\endgroup\$
    – Osable
    Nov 28, 2016 at 8:12
7
\$\begingroup\$

MATL, 22 bytes

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

Try it online!

Explanation

'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
\$\endgroup\$
6
\$\begingroup\$

Jelly, 19 bytes

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

TryItOnline!

How?

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
\$\endgroup\$
2
  • \$\begingroup\$ I like that length-unlength chain in the middle ;-) \$\endgroup\$ Nov 25, 2016 at 23:47
  • \$\begingroup\$ Yeah, J’ (range of length decremented) would also have the same effect, but there is no lowered version of J, and the LḶ is kind of cute :) \$\endgroup\$ Nov 26, 2016 at 5:17
5
\$\begingroup\$

Batch, 142 bytes

@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%%
\$\endgroup\$
5
\$\begingroup\$

Ruby, 46 44 bytes

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

2 bytes saved thanks to G B

\$\endgroup\$
2
  • \$\begingroup\$ puts does not need the whitespace \$\endgroup\$
    – G B
    Nov 25, 2016 at 11:06
  • 1
    \$\begingroup\$ And you can save one more character by decrementing s: instead of ?v*(s-2*i) use ?v*s;s-=2 \$\endgroup\$
    – G B
    Nov 25, 2016 at 11:25
4
\$\begingroup\$

Python, 76 73 bytes

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

Edit: Saved 3 bytes thanks to @TuukkaX and @Challenger5 (Thanks!)

\$\endgroup\$
5
  • 2
    \$\begingroup\$ After the print, there's an useless whitespace :) \$\endgroup\$
    – Yytsi
    Nov 25, 2016 at 4:53
  • 1
    \$\begingroup\$ Why not use a lambda? lambda s,m:"\n".join([' '*(s/2-i/2)+'V'*i for i in range(s,m*2,-2)]) \$\endgroup\$
    – 0WJYxW9FMN
    Nov 25, 2016 at 7:16
  • 1
    \$\begingroup\$ You can put the function code directly after the def f(s,m):, saving two bytes. \$\endgroup\$ Nov 25, 2016 at 20:40
  • \$\begingroup\$ @J843136028 It's the same number of bytes: def f() is 7 lambda is 7. with Challenger5's tip, def is actually shorter. at least if that's what you meant like i think :) \$\endgroup\$
    – cure
    Nov 26, 2016 at 1:21
  • \$\begingroup\$ @nephi But you also remove the print, so it's 4 characters shorter (lambda s,m:"\n".join(...)), as lambdas basically have an implicit return. \$\endgroup\$
    – Artyer
    Nov 27, 2016 at 0:12
3
\$\begingroup\$

JavaScript (ES6), 57 bytes

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

Outputs a trailing newline. If a leading newline is acceptable, then for 54 bytes:

f=(s,m,p=`
`)=>s<m+m?``:p+`v`.repeat(s)+f(s-2,m,p+` `)
\$\endgroup\$
0
3
\$\begingroup\$

Python 2, 63 bytes

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

Turtlèd, 53 bytes

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

Try it online!

Explanation:

@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]
\$\endgroup\$
2
\$\begingroup\$

Java, 138 137 bytes

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);}

Ungolfed:

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);
}

Update: One byte and loop body gone thanks to @ClaytonRamsey.

\$\endgroup\$
1
  • \$\begingroup\$ You can cut down on one byte if you rewrite the for-loop as for(int i=0;i++<l;v+="v"); \$\endgroup\$ Nov 27, 2016 at 3:34
1
\$\begingroup\$

C, 83 bytes

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);}

Ungolfed and usage:

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);

}
\$\endgroup\$
1
\$\begingroup\$

Pyth, 21 bytes

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

A program that takes input of S followed by M, newline-separated, and prints the result.

Test suite

How it works

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
\$\endgroup\$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.