25
\$\begingroup\$

This challenge is about printing a series of growing ASCII-art arrows. I'll describe the pattern in words, but it might be easier to look at what the start of this series looks like:

>
<
->
<-
-->
<--
--->
<---
---->
<----
----->
<-----
------>
<------
...

An arrow with length n contains an arrowhead (< or >) and n-1 dashes (-). A right-facing arrow has the dashes first, then a >. A left-facing arrow starts with <, and is followed by the dashes. The series consists of a length n right-facing arrow followed by a length n left-facing arrow, with n from 1 to infinity.

To complete the challenge, write a program or function that takes one input, an integer i >= 1, and outputs the first i arrows. Arrows are individual, not in right-left pairs, so for i=3 you should output:

>
<
->

You can return a list of strings, or print them one after the other. If printing, the arrows must be delimited by some consistent delimiter, which doesn't have to be a newline as in the example.

This is , so fewest bytes wins.

\$\endgroup\$
  • 2
    \$\begingroup\$ Related. \$\endgroup\$ – AdmBorkBork Dec 12 '18 at 16:23
  • \$\begingroup\$ Can we have spaces before/after each line? \$\endgroup\$ – Olivier Grégoire Dec 12 '18 at 16:54
  • \$\begingroup\$ @OlivierGrégoire Yes, trailing whitespace is ok. \$\endgroup\$ – Pavel Dec 12 '18 at 16:55
  • \$\begingroup\$ And heading whitespace? \$\endgroup\$ – Olivier Grégoire Dec 12 '18 at 16:58
  • \$\begingroup\$ @OlivierGrégoire Yeah, that's fine. \$\endgroup\$ – Pavel Dec 12 '18 at 17:00

46 Answers 46

9
\$\begingroup\$

Canvas, 10 bytes

⇵-×<n¹[↔}]

Try it here!

\$\endgroup\$
  • \$\begingroup\$ I don't know any Canvas, but is that an arrow-drawing builtin I see? kinda looks like it! \$\endgroup\$ – Pavel Dec 12 '18 at 16:03
  • 2
    \$\begingroup\$ is the "reverse horizontally" built-in (also swapping > & <), sadly no arrow built-ins :p \$\endgroup\$ – dzaima Dec 12 '18 at 16:04
8
\$\begingroup\$

R, 69 bytes

for(i in 1:scan()-1)cat('<'[i%%2],rep('-',i/2),'>'[!i%%2],'
',sep='')

Try it online!

  • -5 bytes thanks to @Giuseppe
  • -3 bytes thanks to @Robert S.
\$\endgroup\$
  • \$\begingroup\$ strrep coerces its second argument to integer so you can use / in place of %/% \$\endgroup\$ – Giuseppe Dec 12 '18 at 16:40
  • \$\begingroup\$ you can also get rid of a entirely by indexing over 0...(n-1) instead: Try it online! \$\endgroup\$ – Giuseppe Dec 12 '18 at 16:44
  • \$\begingroup\$ I'm an idiot... thanks ! :D \$\endgroup\$ – digEmAll Dec 12 '18 at 17:17
  • \$\begingroup\$ @Giuseppe :also I just noticed the deleted question of Robert S. I can use rep instead of strrep and save 3 bytes...(facepalm) \$\endgroup\$ – digEmAll Dec 12 '18 at 17:21
8
\$\begingroup\$

Java (JDK), 81 bytes

n->{for(int i=0;i<n;)System.out.printf(i%2<1?"<%s%n":"%s>%n","-".repeat(i++/2));}

Try it online!

Explanations

n->{                  // int-accepting consumer
 for(int i=0;i<n;)    //  for each i from 0 to n-1 included
  System.out.printf(  //   output on stdout with a pattern
   i%2<1              //    if i is even:
    ?"<%s%n"          //     use the left-arrow pattern
    :"%s>%n",         //    else: use the right-arrow pattern
   "-".repeat(i++/2)  //    fill the "%s" in the pattern with i/2 dashes, and increment i
  );                  // 
}                     //
\$\endgroup\$
8
\$\begingroup\$

Haskell, 41 40 bytes

(`take`g">")
g p=p:('<':init p):g('-':p)

Try it online!

Plain old recursion: start with string p = ">", collect p, a < in front of all but the last char of p and a recursive call with one - put in front of p. Take the first n items of this list.

Edit: -1 byte thanks to @xnor.

\$\endgroup\$
  • 1
    \$\begingroup\$ A weird change to save a byte. \$\endgroup\$ – xnor Dec 13 '18 at 5:44
6
\$\begingroup\$

Commodore BASIC V2 (C64), 94 bytes

0inputn:fOi=1ton:oniaN1gO1:?"<";
1on-(i<3)gO2:fOj=1.5toi/2:?"-";:nE
2on-nOiaN1gO3:?">";
3?:nE

Not entirely sure about the byte count, this is based on the text representation for typing the valid program. It's a bit shorter on disk (91 bytes) because BASIC V2 uses a "tokenized" representation of programs.

Online Demo

Slightly "ungolfed":

0 inputn:fori=1ton:oniand1goto1:print"<";    :rem read n from user, loop to n, if odd skip "<"
1 on-(i<3)goto2:forj=1.5toi/2:print"-";:next :rem skip for i<3, print (i-1)/2 times "-"
2 on-notiand1goto3:print">";                 :rem if even skip ">"
3 print:next                                 :rem newline and next loop iteration
\$\endgroup\$
6
\$\begingroup\$

Self-modifying Brainfuck, 55 bytes

Take input as character code.
Only support input up to 255.
Use null character to separate lines.

Coincidentally, all arrow-drawing characters are used as BF commands. Unfortunately, it doesn't save any bytes (currently).

>>,[<<[-<.>>+<]<<.>>.+>>-[<<<<<.>>>>[-<+<.>>].>-<]>]<>-

Try it online!

Explanation

 Code  |              Memory         | Output | Comment
-------+-----------------------------+--------+--------------------------
       | '<' '>' '-' [0]  0   0   0  |        |
>>,    | '<' '>' '-'  0   0  [x]  0  |        |
[      |                             |        |
       | '<' '>' '-'  l   0  [x]  0  |        | l = arrow length
<<[-<  |                             |        | copy l to next cell
.>>+<] |                             |        | and print '-'
       | '<' '>' '-' [0]  l   x   0  | -----  | there are l '-'s
<<.    | '<' [>] '-'  0   l   x   0  | >      |
>>.+   | '<' '>' '-' [1]  l   x   0  | <null> |
>>-    | '<' '>' '-'  1   l  [y]  0  |        | y=x-1
[      |                             |        | execute if y>0
<<<<<. | [<] '>' '-'  1   l   y   0  | <      |
>>>>   | '<' '>' '-'  1  [l]  y   0  |        |
[-<+<. |                             |        |
>>]    | '<' '>' '-'  L  [0]  y   0  | -----  | L=l+1
.      | '<' '>' '-'  L  [0]  y   0  | <null> |
>-<]>] |                             |        | decrement y
<>-    |                             |        | do nothing, used as data
\$\endgroup\$
6
\$\begingroup\$

Python 2, 54 bytes

thanks to the and Jo King for fixing a bug.

k=0
exec"print k%2*'<'+k/2*'-'+~k%2*'>';k+=1;"*input()

Try it online!

\$\endgroup\$
  • 3
    \$\begingroup\$ Your arrows have too many dashes; only every other one should lengthen by a dash. \$\endgroup\$ – xnor Dec 13 '18 at 2:35
  • 1
    \$\begingroup\$ 54 bytes \$\endgroup\$ – tsh Dec 13 '18 at 5:23
5
\$\begingroup\$

Pyth, 17 bytes

m_W%d2+*\-/d2@"><

Output is a list of strings. Try it online here.

m_W%d2+*\-/d2@"><"dQ   Implicit: Q=eval(input())
                       Trailing "dQ inferred
m                  Q   Map [0-Q), as d, using:
          /d2            Floored division of d by 2
       *\-               Repeat "-" the above number of times
      +                  Append to the above...
             @"><"d      Modular index d into "><" - yields ">" for even d, "<" for odd
                         - examples: d=4 gives "-->", d=7 gives "---<"
 _W                      Reverse the above if...
   %d2                   ... (d % 2) != 0
                       Implicit print result of the map
\$\endgroup\$
5
\$\begingroup\$

PowerShell, 62 56 50 bytes

param($n)(0..$n|%{($j='-'*$_)+'>';"<$j"})[0..--$n]

Try it online!

Loops from 0 up to input $n, each iteration creating two arrow strings. Those are then indexed with 0..--$n to pull out the correct number of elements.

Saved 6 bytes thanks to KGlasier.

\$\endgroup\$
  • \$\begingroup\$ Messing around with my own solution I found a way to cut a few bytes on yours: Can save 4 bytes by wrapping the loop in brackets and indexing directly. ie param($n)(0..$n|%{($j='-'*$_++)+'>';"<$j"})[0..--$n]. So now you don't have to write $x twice. \$\endgroup\$ – KGlasier Dec 12 '18 at 17:00
  • \$\begingroup\$ Also you can save two more bytes by not using ++ in ($j='-'*$_++) as you don't use $_ anywhere else. \$\endgroup\$ – KGlasier Dec 12 '18 at 17:03
  • 1
    \$\begingroup\$ @KGlasier Awesome - thanks for the obvious golfs! :) \$\endgroup\$ – AdmBorkBork Dec 12 '18 at 17:16
5
\$\begingroup\$

Python 3, 53 bytes

My first codegolf answer.

lambda x:[i%2*"<"+i//2*"-"+~i%2*">"for i in range(x)]

-10 bytes thanks to Jo King

\$\endgroup\$
5
\$\begingroup\$

Haskell, 51 44 bytes

-7 bytes thanks to xnor (using iterate over list-comprehension)!

(`take`do b<-iterate('-':)"";[b++">",'<':b])

Try it online!

Explanation / Ungolfed

Using do-notation saves us a concat, and using infix-notation allows a pointfree function with take, undoing these would give:

f n = take n $ concat [ [b++">", '<':b] | b <- iterate ('-':) "" ]
\$\endgroup\$
5
\$\begingroup\$

Japt -m, 16 15 13 12 bytes

Saved 1 byte thanks to Shaggy

g<i>)iUUz ç-

Test it online

Explanation:

-m            // Map the program through [0...Input); U becomes the iterative number
g<i>)iUUz ç-  
 <i>          // ">" prepended with "<", creating "><"
g             //   Get the char at index U, with index-wrapping
    i         // Insert:
     U        //   At index U, with index-wrapping
         ç-   //   "-" repeated:
      Uz      //     U/2 times
\$\endgroup\$
  • 1
    \$\begingroup\$ 12 bytes \$\endgroup\$ – Shaggy Jan 15 at 23:59
  • \$\begingroup\$ @Shaggy Ha! Very clever, thanks! \$\endgroup\$ – Oliver Jan 16 at 0:15
4
\$\begingroup\$

Jelly, 15 bytes

ị⁾><;’H”-ẋƲṚ⁸¡)

Try it online!

\$\endgroup\$
  • \$\begingroup\$ -1 byte using tie: TIO. \$\endgroup\$ – HyperNeutrino Dec 14 '18 at 14:29
4
\$\begingroup\$

MathGolf, 17 15 bytes

Saved 2 bytes thanks to Jo King and Kevin Cruijssen

{ï½'-*'>ï¥╛Å⌡\n

Try it online!

Explanation

The 15-byte approach is different compared to my original solution, I can't take any credit for the implementation.

{                 start block or arbitrary length
 ï                index of current loop, or length of last loop
  ½               pop a : push(a//2 if int else a/2)
   '-             push single character "-"
     *            pop a, b : push(a*b)
      '>           push single character ">"
        ï         index of current loop, or length of last loop
         ¥        modulo 2
          ╛       if without else
           Å      start block of length 2
            ⌡     decrement twice
             \    swap top elements
              n   newline char, or map array with newlines
\$\endgroup\$
  • \$\begingroup\$ How does the if/else work in MathGolf? I know how the if-without-else and else-without-if statements work, but how to create an if{ ... } else{ ... } in MathGolf with ¿? (Maybe I should post this in the chat instead of here.. But I might perhaps have a save of 1 byte if I can fix the if-else.) \$\endgroup\$ – Kevin Cruijssen Dec 13 '18 at 10:20
  • 1
    \$\begingroup\$ @KevinCruijssen I think it works with the next two commands/blocks. e.g. ¿12 will push 1 if true, else 2, ¿Å3*Å1+ will add one if true else triple the next element \$\endgroup\$ – Jo King Dec 13 '18 at 10:30
  • \$\begingroup\$ @KevinCruijssen The if/else pops two operators or blocks from the code. Jo King is correct in his example, but you could also do ¿{"foo"}{"bar"} or ¿1{2}. \$\endgroup\$ – maxb Dec 13 '18 at 10:34
  • \$\begingroup\$ @JoKing I'll add a TODO to fix the docs for the slicing operators. \$\endgroup\$ – maxb Dec 13 '18 at 10:35
  • 1
    \$\begingroup\$ 15 bytes using @KevinCruijssen's solution \$\endgroup\$ – Jo King Dec 13 '18 at 10:46
4
\$\begingroup\$

Japt -m, 14 bytes

"<>"¬hUUz ç-)q

Try it online!

Updated with a completely new method.

Explanation:

                  #Implicitly map over the range [0..input) as U
"<>"              #The string "<>"
    ¬             #Split into the array ["<",">"]
     hU     )     #Replace the element at index U with wrapping:
           -      # The character '-'
          ç       # Repeated a number of times equal to
       Uz         #  U integer divided by 2
             q    #Join the array to a string
\$\endgroup\$
  • 1
    \$\begingroup\$ ç auto-casts its first parameter into a string, so you can drop the '. \$\endgroup\$ – Oliver Dec 13 '18 at 0:21
  • 1
    \$\begingroup\$ You don't need the u method thanks to index wrapping so this can be 14 bytes. \$\endgroup\$ – Shaggy Dec 13 '18 at 8:13
4
\$\begingroup\$

C (gcc), 80 77 76 74 71 bytes

g(n,i,j){--n&&g(n);for(j=n%2,i=n/=2;putchar(~n?n---i*j?45:62-j*2:0););}

Try it online!

-3 bytes with idea from ASCII-only.

-1 with \0 instead of \n

-5 rearranging parts


Output includes a trailing \0.

g(n,i,j){
    --n&&g(n);              //draw smaller arrows first (if n>1)
    for(j=n%2,i=n/=2;       //j:!(input parity); i:arrow len-1=ceil(input)/2-1
        putchar(~n          //if n>=0, arrow is not yet completed
                ? n---i*j   //if not first (j==1) or last (j==0) char of arrow:
                  ? 45      // output '-'
                  : 62-j*2  // otherwise, output the appropriate arrow head
                : 0););     //\0 after arrow complete. putchar returns 0; loop terminates
}
\$\endgroup\$
  • \$\begingroup\$ this might be clearer? idk \$\endgroup\$ – ASCII-only Jan 12 at 7:12
  • \$\begingroup\$ so close :/ \$\endgroup\$ – ASCII-only Jan 12 at 7:52
  • \$\begingroup\$ @ASCII-only Yeah, that should be clearer, even if it doesn't make a difference for bytecount. As for that second point.. thanks for the idea! Managed to trim down to 78 with that. \$\endgroup\$ – attinat Jan 12 at 8:02
  • \$\begingroup\$ sadly, combining ternaries doesn't help \$\endgroup\$ – ASCII-only Jan 12 at 8:18
  • \$\begingroup\$ XD you still have !n-- in the first codeblock \$\endgroup\$ – ASCII-only Jan 12 at 8:22
3
\$\begingroup\$

JavaScript (ES6), 58 bytes

Returns a space-separated string.

n=>(g=p=>n--?k++&1?`<${p} `+g(p+'-'):p+'> '+g(p):'')(k='')

Try it online!

\$\endgroup\$
3
\$\begingroup\$

SNOBOL4 (CSNOBOL4), 123 122 118 bytes

	N =INPUT - 1
P	H =X / 2
	Y =DUPL('-',H)
	OUTPUT =EQ(H,X - H) Y '>'	:S(I)
	OUTPUT ='<' Y
I	X =LT(X,N) X + 1	:S(P)
END	

Try it online!

\$\endgroup\$
3
\$\begingroup\$

V, 22 bytes

i>
<Àñäkjjé-já-ñÀGjdG

Try it online!

\$\endgroup\$
  • 5
    \$\begingroup\$ This looks like some weird scandinavian language \$\endgroup\$ – Pavel Dec 12 '18 at 18:02
3
\$\begingroup\$

Charcoal, 16 bytes

NθFθ«⊘ι↓>‖T»Fθ‖T

Try it online! Link is to verbose version of code. I had three 17-byte solutions before I eventually stumbled over this one. Explanation:

Nθ

Input n.

Fθ«

Repeat n times, 0-indexed.

⊘ι

Draw a line of -s of length half the index (truncated).

↓>

Draw the arrowhead and move to the next line.

‖T»

Reflect everything, flipping the arrowheads.

Fθ‖T

The above loop has n reflections, but we need an even number of reflections, so perform another n reflections.

\$\endgroup\$
3
\$\begingroup\$

Clean, 76 73 bytes

import StdEnv,StdLib
$n=take n[s\\i<-inits['--'..],s<-[i++['>'],['<':i]]]

Try it online!

Uses the neat fact that ['-','-'..] is the same as ['--'..] to save a bit.

\$\endgroup\$
3
\$\begingroup\$

JavaScript, 49 bytes

f=n=>--n?f(n,l='')+(n%2?`
<`+l:`
${l+='-'}>`):'>'

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Wow, pretty cool \$\endgroup\$ – Levitator Imbalance Dec 14 '18 at 10:41
  • \$\begingroup\$ ...but it throws on 10000, meanwhile my ES6 solution is still works :D Anyway, your solution is very cool) \$\endgroup\$ – Levitator Imbalance Dec 14 '18 at 10:53
2
\$\begingroup\$

Powershell, 51 bytes

param($n)0..$n|%{'-'*$_+'>';'<'+'-'*$_}|?{$n---gt0}
\$\endgroup\$
2
\$\begingroup\$

6502 machine code (C64), 49 bytes

00 C0 20 9B B7 A2 00 8A 4A A8 90 05 A9 3C 20 D2 FF A9 2D C0 00 F0 06 20 D2 FF 
88 D0 FA 8A 4A B0 05 A9 3E 20 D2 FF A9 0D 20 D2 FF E8 E4 65 D0 D7 60

Still quite a bit shorter than BASIC ;) This one has a number range only up to 255 because the natural integer size of the machine has only 8 bits.

Online demo

Usage: SYS49152,[n] (e.g. SYS49152,3 for the example from the challenge)

Commented disassembly:

         00 C0       .WORD $C000        ; load address
.C:c000  20 9B B7    JSR $B79B          ; get unsigned byte from commandline
.C:c003  A2 00       LDX #$00           ; main loop counter
.C:c005   .loop:
.C:c005  8A          TXA                ; loop counter to accumulator
.C:c006  4A          LSR A              ; divide by 2, shift lowest bit to C
.C:c007  A8          TAY                ; result to Y
.C:c008  90 05       BCC .toright       ; C clear -> counter even, skip '<'
.C:c00a  A9 3C       LDA #$3C           ; load character '<'
.C:c00c  20 D2 FF    JSR $FFD2          ; output character
.C:c00f   .toright:
.C:c00f  A9 2D       LDA #$2D           ; load character '-'
.C:c011  C0 00       CPY #$00           ; counter/2 == 0 ? then no dashes
.C:c013  F0 06       BEQ .skipdashes
.C:c015   .printdashes:
.C:c015  20 D2 FF    JSR $FFD2          ; output character
.C:c018  88          DEY                ; decrement Y
.C:c019  D0 FA       BNE .printdashes   ; not 0 yet -> repeat
.C:c01b   .skipdashes:
.C:c01b  8A          TXA                ; loop counter to accumulator
.C:c01c  4A          LSR A              ; shift lowest bit to C
.C:c01d  B0 05       BCS .toleft        ; C set -> counter odd, skip '>'
.C:c01f  A9 3E       LDA #$3E           ; load character '>'
.C:c021  20 D2 FF    JSR $FFD2          ; output character
.C:c024   .toleft:
.C:c024  A9 0D       LDA #$0D           ; load newline character
.C:c026  20 D2 FF    JSR $FFD2          ; output character
.C:c029  E8          INX                ; next loop iteration
.C:c02a  E4 65       CPX $65            ; compare to command line argument
.C:c02c  D0 D7       BNE .loop          ; not reached yet -> repeat main loop
.C:c02e  60          RTS                ; exit
\$\endgroup\$
2
\$\begingroup\$

Perl 6, 39 bytes

{map {'<'x$_%2~'-'x$_/2~'>'x$_%%2},^$_}

Try it online!

Anonymous code block that returns a list of lines.

\$\endgroup\$
2
\$\begingroup\$

K (ngn/k), 31 29 bytes

{"<->"x#2,x{(1=*x)_1,2-|x}\0}

Try it online!

first we generate lists with 0 instead of "<", 1 instead of "-", and 2 instead of ">":

{ } function with argument x

x{...}\0 apply the inner function x times, starting with an initial value of 0 and preserving intermediate results

|x reverse

2- replace 0 with 2 and vice versa, keep the 1s as they are

1, prepend a 1

(1=*x)_ is the first of x equal to 1? if yes, drop one element, otherwise drop 0 elements (do nothing)

2, prepend a 2 for the initial ">" arrow

x# we have a little too many lists, so take only the first x of them

"<->" use the lists' elements (0/1/2) as indices in this string

\$\endgroup\$
  • \$\begingroup\$ I would like to ask for an explanation (I haven't started learning K yet, I don't know which version to start with...) \$\endgroup\$ – Galen Ivanov Dec 13 '18 at 12:14
  • 1
    \$\begingroup\$ @GalenIvanov i tried to write an explanation, i hope it makes sense. thanks for your interest in my favourite language :) there are multiple implementations with different advantages and disadvantages (kx's original, kona, oK and i'm working on my own). would you like to join the apl chat room so i can give you more details? \$\endgroup\$ – ngn Dec 13 '18 at 12:44
  • \$\begingroup\$ Thank you, I'm already there \$\endgroup\$ – Galen Ivanov Dec 13 '18 at 12:49
2
\$\begingroup\$

05AB1E, 23 20 bytes

FNÉD„><è'-N;∍«s_iR},

Try it online!

First time using 05AB1E or any other golfing language for that matter. Any ideas welcome.

-3 from Kevin Cruijssen

\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to the world of 05AB1E, and nice first answer. +1 from me. :) "><" can be „>< to save a byte. There are builtins for 1, 2, and 3 char strings, being ', , and respectively. Here is a 18 bytes alternative I came up with, but perhaps it could be golfed a bit more. If you haven't seen it yet, we have a tips for golfing in 05AB1E page, and also feel free to ask anything in the chat. \$\endgroup\$ – Kevin Cruijssen Dec 13 '18 at 8:54
  • 1
    \$\begingroup\$ @KevinCruijssen Thanks so much for your ideas. I don't feel right just using your code, as it feels fairly different from mine, but I did use the idea of modulo 2 as checking for if a number is odd. I also use the two char string idea. I would not mind at all if you posted the 18 byte version on your own. \$\endgroup\$ – nedla2004 Dec 13 '18 at 23:09
  • \$\begingroup\$ I've posted my answer in that case. :) \$\endgroup\$ – Kevin Cruijssen Dec 14 '18 at 8:31
2
\$\begingroup\$

C# (.NET Core), 90 bytes

a=>{for(int i=0;i<a;i++){var s=new String('-',i/2);Console.WriteLine(i%2<1?s+">":"<"+s);}}

Try it online!

Uses an Action delegate to pull in the input and not require a return.

Ungolfed:

a => {
    for(int i = 0; i < a; i++)          // from [0, a)
    {
        var s = new String('-', i / 2);     // create string of dashes of length (a / 2)
        Console.WriteLine(i % 2 < 1 ?       // write arrow
                                s + ">" :       // if i is even: dashes plus ">"
                                "<" + s);       // if i is odd: "<" plus dashes
    }
}
\$\endgroup\$
2
\$\begingroup\$

ES6, 96 82 79 70 bytes

Try it online! (Thanks to @Oliver)

n=>[...Array(n)].map((_,i)=>(i%2?"<":"")+"-".repeat(i/2)+(i%2?"":">"))
\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to PPCG! By default, taking input as a variable is disallowed; you have to either make it a function (just stick a i=> in front of your code!) or from a command-line argument or STDIN or something. \$\endgroup\$ – HyperNeutrino Dec 14 '18 at 14:40
  • \$\begingroup\$ @HyperNeutrino okay, edited answer. However, the most voted answer contains only the body of the function, but ok. Anyway I'm outsider) \$\endgroup\$ – Levitator Imbalance Dec 14 '18 at 15:09
  • \$\begingroup\$ Can you link it? I don't think any of them are invalid, at least not the top few. \$\endgroup\$ – HyperNeutrino Dec 14 '18 at 15:16
  • 1
    \$\begingroup\$ A few more bytes: Try it online \$\endgroup\$ – Oliver Dec 14 '18 at 16:15
  • 1
    \$\begingroup\$ A few more bytes if you re-arrange that last ternary operator and remove the center parenthesis: Try it online \$\endgroup\$ – Oliver Dec 14 '18 at 16:59
2
\$\begingroup\$

Red, 109 108 bytes

-1 byte thanks to NK1406

func[n][repeat i n[print reduce[pick[pad/with pad/left/with]k: i% 2 + 1
pick copy"<>"k i / 2 + k - 1 #"-"]]]

Try it online!

\$\endgroup\$
  • 1
    \$\begingroup\$ -1 for removing a space \$\endgroup\$ – NK1406 Dec 15 '18 at 18:28
  • \$\begingroup\$ @NK1406 Thank you! I didn't know this is valid. \$\endgroup\$ – Galen Ivanov Dec 15 '18 at 19:01

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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