13
\$\begingroup\$

Specifications

Given a number n, output an ASCII "meme arrow" (greater-than symbol, >) of size n.

n will always be a positive integer, greater than 0.

Examples

n = 2

\
 \
 /
/

n = 5

\
 \
  \
   \
    \
    /
   /
  /
 /
/

Sample code

Here is a sample program, written in Crystal, that returns the correct results. Run it as ./arrow 10.

arrow.cr:

def f(i)
        i.times { |j|
                j.times { print ' ' }
                puts "\\"
        }
        i.times { |j|
                (i-j-1).times { print ' ' }
                puts '/'
        }
end

f(ARGV[0].to_i)

Rules

  • This is . The shortest answer wins. However, I will not select an answer, because the shortest answer may change over time.
  • Standard loopholes are not allowed.
\$\endgroup\$
  • 1
    \$\begingroup\$ Are you sure this is not a duplicate (that is, did you sandbox this)? I think this is likely to be, but it's slightly nearly impossible to search for. \$\endgroup\$ – my pronoun is monicareinstate Jun 9 at 4:46
  • 1
    \$\begingroup\$ Can n be zero? \$\endgroup\$ – xnor Jun 9 at 6:05
  • 6
    \$\begingroup\$ I think it's pretty silly to call this common symbol a "meme arrow". They're obviously comedy chevrons. \$\endgroup\$ – scatter Jun 10 at 18:04
  • 4
    \$\begingroup\$ @Christian They're actually amusing angles \$\endgroup\$ – dkudriavtsev Jun 10 at 20:39
  • 1
    \$\begingroup\$ @ArtemisFowl I thought they were interesting increases \$\endgroup\$ – dkudriavtsev Jun 12 at 22:17

40 Answers 40

0
\$\begingroup\$

Java 8, 80 bytes

n->{for(int i=0;i<2*n;)System.out.printf("%"+(i++<n?i:n-~n-i)+"c\n",i>n?47:92);}

Try it online.

Explanation:

n->{                    // Method with integer parameter and no return-type
  for(int i=0;i<2*n;)   //  Loop `i` in the range [0, 2 * input `n`):
    System.out.printf(  //   Print with format:
      "%"+(i++<n?       //    If `i` is smaller than input `n`:
                        //    (and increase `i` by 1 right after this check with `i++`)
            i           //     Use `i` leading spaces
           :            //    Else:
            n-~n-i)     //     Use `2 * n - i + 1` leading spaces
      +"c\n",i>n?       //    If `i` is larger than input `n`:
              47        //     Append a trailing '/' and newline
             :          //    Else:
              92);}     //     Append a trailing '\' and newline
\$\endgroup\$
0
\$\begingroup\$

Japt -R, 15 bytes

"\\/"¬c@õ!ùX zY

Try it

õ!ù'\ cUÆ'/ ùU´

Try it

\$\endgroup\$
0
\$\begingroup\$

Pyth, 23 bytes

V2VQ
+*?N--QH1H\ ?N\/\\

Try it online!

Note that the program must not have a terminating newline! If saving it on linux, you can remove the last byte in a file using head -c -1 <file>.

I think this is the first time I have used for loops in pyth? Anyways, this is a rather direct port of the example source code in the question (though the 2 loops are combined, and the innermost loop is converted into string multiplication, and the remaining 2 prints are joined into one).

\$\endgroup\$
0
\$\begingroup\$

Pyth, 19 bytes

VQ+*dN\\)V_Q+*dhN\/

Try it online!

TIL multiplying a string by a negative value multiplies it by its absolute value.

\$\endgroup\$
0
\$\begingroup\$

Batch File, 117 + 9 bytes

Executed using cmd/v/q/c.

for /l %%i in (1,1,%1)do (for /l %%j in (2,1,%%i)do set %%i= !%%i!)&echo !%%i!\
for /l %%i in (%1,-1,1)do echo !%%i!/
\$\endgroup\$
0
\$\begingroup\$

Pyth, 18 bytes

js.e+R?k\/\\b_B*L;

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Python 3.8 (pre-release), 80 bytes

lambda n:'\n'.join([' '*i+'\\'for i in(r:=range(n))]+[' '*(n+~i)+'/'for i in r])

Try it online!

Same approach as the one I suggested to @Artemis Fowl, but takes advantage of the walrus operator.

\$\endgroup\$
0
\$\begingroup\$

Swift 5/Xcode 10.2.1, 91 bytes

(0..<n*2).map{String(repeating:" ",count:$0<n ?$0:n*2-$0-1)+($0<n ?"\\":"/")+"\n"}.joined()   

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Pepe, 91 bytes

rErEeEeEEEeeREeEREErereeereeERrEeeEeeeeeRrEeeeReereRerEEEererEeeEeEEEErEEEEREErereeereeERee

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Perl 5, 59 bytes

$_--;say$"x$_."\\"for(0..$_);say$"x$_."/"for(reverse 0..$_)

Example execution:

perl -nE '$_--;say$"x$_."\\"for(0..$_);say$"x$_."/"for(reverse 0..$_)'

Waits for an integer to be provided on STDIN when executed. Once provided, it will display the arrow.

\$\endgroup\$

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.