Draw some expanding arrows
up vote
14
down vote
favorite
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 code-golf, so fewest bytes wins.
code-golf ascii-art sequence
add a comment |
up vote
14
down vote
favorite
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 code-golf, so fewest bytes wins.
code-golf ascii-art sequence
1
Related.
– AdmBorkBork
10 hours ago
Can we have spaces before/after each line?
– Olivier Grégoire
10 hours ago
@OlivierGrégoire Yes, trailing whitespace is ok.
– Pavel
10 hours ago
And heading whitespace?
– Olivier Grégoire
10 hours ago
@OlivierGrégoire Yeah, that's fine.
– Pavel
10 hours ago
add a comment |
up vote
14
down vote
favorite
up vote
14
down vote
favorite
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 code-golf, so fewest bytes wins.
code-golf ascii-art sequence
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 code-golf, so fewest bytes wins.
code-golf ascii-art sequence
code-golf ascii-art sequence
asked 11 hours ago
Pavel
4,76313288
4,76313288
1
Related.
– AdmBorkBork
10 hours ago
Can we have spaces before/after each line?
– Olivier Grégoire
10 hours ago
@OlivierGrégoire Yes, trailing whitespace is ok.
– Pavel
10 hours ago
And heading whitespace?
– Olivier Grégoire
10 hours ago
@OlivierGrégoire Yeah, that's fine.
– Pavel
10 hours ago
add a comment |
1
Related.
– AdmBorkBork
10 hours ago
Can we have spaces before/after each line?
– Olivier Grégoire
10 hours ago
@OlivierGrégoire Yes, trailing whitespace is ok.
– Pavel
10 hours ago
And heading whitespace?
– Olivier Grégoire
10 hours ago
@OlivierGrégoire Yeah, that's fine.
– Pavel
10 hours ago
1
1
Related.
– AdmBorkBork
10 hours ago
Related.
– AdmBorkBork
10 hours ago
Can we have spaces before/after each line?
– Olivier Grégoire
10 hours ago
Can we have spaces before/after each line?
– Olivier Grégoire
10 hours ago
@OlivierGrégoire Yes, trailing whitespace is ok.
– Pavel
10 hours ago
@OlivierGrégoire Yes, trailing whitespace is ok.
– Pavel
10 hours ago
And heading whitespace?
– Olivier Grégoire
10 hours ago
And heading whitespace?
– Olivier Grégoire
10 hours ago
@OlivierGrégoire Yeah, that's fine.
– Pavel
10 hours ago
@OlivierGrégoire Yeah, that's fine.
– Pavel
10 hours ago
add a comment |
23 Answers
23
active
oldest
votes
up vote
6
down vote
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.
strrep
coerces its second argument tointeger
so you can use/
in place of%/%
– Giuseppe
10 hours ago
you can also get rid ofa
entirely by indexing over0...(n-1)
instead: Try it online!
– Giuseppe
10 hours ago
I'm an idiot... thanks ! :D
– digEmAll
9 hours ago
@Giuseppe :also I just noticed the deleted question of Robert S. I can use rep instead of strrep and save 3 bytes...(facepalm)
– digEmAll
9 hours ago
add a comment |
up vote
4
down vote
Canvas, 10 bytes
⇵-×<n¹[↔}]
Try it here!
I don't know any Canvas, but is that an arrow-drawing builtin I see?↔
kinda looks like it!
– Pavel
11 hours ago
↔
is the "reverse horizontally" built-in (also swapping>
&<
), sadly no arrow built-ins :p
– dzaima
11 hours ago
add a comment |
up vote
4
down vote
Python 2, 53 bytes
k=-1
exec"print'<'[k%2:]+'-'*k+k%2*'>';k+=1;"*input()
Try it online!
Your arrows have too many dashes; only every other one should lengthen by a dash.
– xnor
33 mins ago
add a comment |
up vote
3
down vote
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
add a comment |
up vote
3
down vote
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
add a comment |
up vote
3
down vote
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.
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. ieparam($n)(0..$n|%{($j='-'*$_++)+'>';"<$j"})[0..--$n]
. So now you don't have to write$x
twice.
– KGlasier
10 hours ago
Also you can save two more bytes by not using++
in($j='-'*$_++)
as you don't use$_
anywhere else.
– KGlasier
10 hours ago
1
@KGlasier Awesome - thanks for the obvious golfs! :)
– AdmBorkBork
9 hours ago
add a comment |
up vote
3
down vote
Jelly, 15 bytes
ị⁾><;’H”-ẋƲṚ⁸¡)
Try it online!
add a comment |
up vote
2
down vote
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 pattern with i/2 dashes, and increment i
); //
} //
add a comment |
up vote
2
down vote
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!
add a comment |
up vote
2
down vote
V, 22 bytes
i>
<Àñäkjjé-já-ñÀGjdG
Try it online!
2
This looks like some weird scandinavian language
– Pavel
9 hours ago
add a comment |
up vote
2
down vote
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.
add a comment |
up vote
2
down vote
Japt -m
, 16 bytes
"<>"¬hUu Uz ç-)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 ["<",">"]
hUu ) #Replace the element at index U modulo 2 with:
- # The character '-'
ç # Repeated a number of times equal to
Uz # U integer divided by 2
q #Join the array to a string
1
ç
auto-casts its first parameter into a string, so you can drop the'
.
– Oliver
2 hours ago
add a comment |
up vote
1
down vote
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!
add a comment |
up vote
1
down vote
Haskell, 51 bytes
(`take`do b<-['-'<$[1..n]|n<-[0..]];[b++">",'<':b])
Try it online!
Explanation / Ungolfed
Using do
-notation saves us a concat
, using '-'<$[1..n]
is shorter than replicate
, and finally using infix-notation allows a pointfree function with take
, undoing these would give:
f n = take n $ concat [ [b++">", '<':b] | n<-[0..], let b = replicate n '-' ]
add a comment |
up vote
1
down vote
Haskell, 41 bytes
(`take`g"")
g p=(p++">"):('<':p):g('-':p)
Try it online!
Plain old recursion: start with an emtpy string p
, collect p
with a right arrow, a left arrow with p
and a recursive call with p
one -
longer. Take the first n
items of this list.
add a comment |
up vote
1
down vote
Powershell, 51 bytes
param($n)0..$n|%{'-'*$_+'>';'<'+'-'*$_}|?{$n---gt0}
add a comment |
up vote
1
down vote
05AB1E, 23 bytes
FN2%D"><"è'-N2÷∍«s_iR},
Try it online!
First time using 05AB1E or any other golfing language for that matter. Any ideas welcome.
add a comment |
up vote
1
down vote
Java 123 bytes
n->{String l="",r="";for(int c=0;c<n;c++)System.out.println(c%2==0?r=c==0?">":c==1?"<":"-"+r:(l+=c==0?">":c==1?"<":"-"));}
add a comment |
up vote
1
down vote
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.
add a comment |
up vote
1
down vote
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
add a comment |
up vote
1
down vote
Perl 5, 44 bytes
map{$_/=2;say'<'x/./,'-'x$_,'>'x!$&}0..<>-1
Try it online!
add a comment |
up vote
1
down vote
Japt -m
, 16 15 13 bytes
g"><" iUUz ç-
Test it online
add a comment |
up vote
0
down vote
Perl 6, 39 bytes
{map {'<'x$_%2~'-'x$_/2~'>'x$_%%2},^$_}
Try it online!
Anonymous code block that returns a list of lines.
add a comment |
23 Answers
23
active
oldest
votes
23 Answers
23
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
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.
strrep
coerces its second argument tointeger
so you can use/
in place of%/%
– Giuseppe
10 hours ago
you can also get rid ofa
entirely by indexing over0...(n-1)
instead: Try it online!
– Giuseppe
10 hours ago
I'm an idiot... thanks ! :D
– digEmAll
9 hours ago
@Giuseppe :also I just noticed the deleted question of Robert S. I can use rep instead of strrep and save 3 bytes...(facepalm)
– digEmAll
9 hours ago
add a comment |
up vote
6
down vote
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.
strrep
coerces its second argument tointeger
so you can use/
in place of%/%
– Giuseppe
10 hours ago
you can also get rid ofa
entirely by indexing over0...(n-1)
instead: Try it online!
– Giuseppe
10 hours ago
I'm an idiot... thanks ! :D
– digEmAll
9 hours ago
@Giuseppe :also I just noticed the deleted question of Robert S. I can use rep instead of strrep and save 3 bytes...(facepalm)
– digEmAll
9 hours ago
add a comment |
up vote
6
down vote
up vote
6
down vote
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.
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.
edited 9 hours ago
answered 10 hours ago
digEmAll
2,36148
2,36148
strrep
coerces its second argument tointeger
so you can use/
in place of%/%
– Giuseppe
10 hours ago
you can also get rid ofa
entirely by indexing over0...(n-1)
instead: Try it online!
– Giuseppe
10 hours ago
I'm an idiot... thanks ! :D
– digEmAll
9 hours ago
@Giuseppe :also I just noticed the deleted question of Robert S. I can use rep instead of strrep and save 3 bytes...(facepalm)
– digEmAll
9 hours ago
add a comment |
strrep
coerces its second argument tointeger
so you can use/
in place of%/%
– Giuseppe
10 hours ago
you can also get rid ofa
entirely by indexing over0...(n-1)
instead: Try it online!
– Giuseppe
10 hours ago
I'm an idiot... thanks ! :D
– digEmAll
9 hours ago
@Giuseppe :also I just noticed the deleted question of Robert S. I can use rep instead of strrep and save 3 bytes...(facepalm)
– digEmAll
9 hours ago
strrep
coerces its second argument to integer
so you can use /
in place of %/%
– Giuseppe
10 hours ago
strrep
coerces its second argument to integer
so you can use /
in place of %/%
– Giuseppe
10 hours ago
you can also get rid of
a
entirely by indexing over 0...(n-1)
instead: Try it online!– Giuseppe
10 hours ago
you can also get rid of
a
entirely by indexing over 0...(n-1)
instead: Try it online!– Giuseppe
10 hours ago
I'm an idiot... thanks ! :D
– digEmAll
9 hours ago
I'm an idiot... thanks ! :D
– digEmAll
9 hours ago
@Giuseppe :also I just noticed the deleted question of Robert S. I can use rep instead of strrep and save 3 bytes...(facepalm)
– digEmAll
9 hours ago
@Giuseppe :also I just noticed the deleted question of Robert S. I can use rep instead of strrep and save 3 bytes...(facepalm)
– digEmAll
9 hours ago
add a comment |
up vote
4
down vote
Canvas, 10 bytes
⇵-×<n¹[↔}]
Try it here!
I don't know any Canvas, but is that an arrow-drawing builtin I see?↔
kinda looks like it!
– Pavel
11 hours ago
↔
is the "reverse horizontally" built-in (also swapping>
&<
), sadly no arrow built-ins :p
– dzaima
11 hours ago
add a comment |
up vote
4
down vote
Canvas, 10 bytes
⇵-×<n¹[↔}]
Try it here!
I don't know any Canvas, but is that an arrow-drawing builtin I see?↔
kinda looks like it!
– Pavel
11 hours ago
↔
is the "reverse horizontally" built-in (also swapping>
&<
), sadly no arrow built-ins :p
– dzaima
11 hours ago
add a comment |
up vote
4
down vote
up vote
4
down vote
Canvas, 10 bytes
⇵-×<n¹[↔}]
Try it here!
Canvas, 10 bytes
⇵-×<n¹[↔}]
Try it here!
answered 11 hours ago
dzaima
14.3k21754
14.3k21754
I don't know any Canvas, but is that an arrow-drawing builtin I see?↔
kinda looks like it!
– Pavel
11 hours ago
↔
is the "reverse horizontally" built-in (also swapping>
&<
), sadly no arrow built-ins :p
– dzaima
11 hours ago
add a comment |
I don't know any Canvas, but is that an arrow-drawing builtin I see?↔
kinda looks like it!
– Pavel
11 hours ago
↔
is the "reverse horizontally" built-in (also swapping>
&<
), sadly no arrow built-ins :p
– dzaima
11 hours ago
I don't know any Canvas, but is that an arrow-drawing builtin I see?
↔
kinda looks like it!– Pavel
11 hours ago
I don't know any Canvas, but is that an arrow-drawing builtin I see?
↔
kinda looks like it!– Pavel
11 hours ago
↔
is the "reverse horizontally" built-in (also swapping >
& <
), sadly no arrow built-ins :p– dzaima
11 hours ago
↔
is the "reverse horizontally" built-in (also swapping >
& <
), sadly no arrow built-ins :p– dzaima
11 hours ago
add a comment |
up vote
4
down vote
Python 2, 53 bytes
k=-1
exec"print'<'[k%2:]+'-'*k+k%2*'>';k+=1;"*input()
Try it online!
Your arrows have too many dashes; only every other one should lengthen by a dash.
– xnor
33 mins ago
add a comment |
up vote
4
down vote
Python 2, 53 bytes
k=-1
exec"print'<'[k%2:]+'-'*k+k%2*'>';k+=1;"*input()
Try it online!
Your arrows have too many dashes; only every other one should lengthen by a dash.
– xnor
33 mins ago
add a comment |
up vote
4
down vote
up vote
4
down vote
Python 2, 53 bytes
k=-1
exec"print'<'[k%2:]+'-'*k+k%2*'>';k+=1;"*input()
Try it online!
Python 2, 53 bytes
k=-1
exec"print'<'[k%2:]+'-'*k+k%2*'>';k+=1;"*input()
Try it online!
answered 10 hours ago
ovs
18.6k21059
18.6k21059
Your arrows have too many dashes; only every other one should lengthen by a dash.
– xnor
33 mins ago
add a comment |
Your arrows have too many dashes; only every other one should lengthen by a dash.
– xnor
33 mins ago
Your arrows have too many dashes; only every other one should lengthen by a dash.
– xnor
33 mins ago
Your arrows have too many dashes; only every other one should lengthen by a dash.
– xnor
33 mins ago
add a comment |
up vote
3
down vote
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
add a comment |
up vote
3
down vote
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
add a comment |
up vote
3
down vote
up vote
3
down vote
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
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
answered 10 hours ago
Sok
3,469722
3,469722
add a comment |
add a comment |
up vote
3
down vote
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
add a comment |
up vote
3
down vote
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
add a comment |
up vote
3
down vote
up vote
3
down vote
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
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
answered 10 hours ago
Felix Palmen
3,271525
3,271525
add a comment |
add a comment |
up vote
3
down vote
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.
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. ieparam($n)(0..$n|%{($j='-'*$_++)+'>';"<$j"})[0..--$n]
. So now you don't have to write$x
twice.
– KGlasier
10 hours ago
Also you can save two more bytes by not using++
in($j='-'*$_++)
as you don't use$_
anywhere else.
– KGlasier
10 hours ago
1
@KGlasier Awesome - thanks for the obvious golfs! :)
– AdmBorkBork
9 hours ago
add a comment |
up vote
3
down vote
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.
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. ieparam($n)(0..$n|%{($j='-'*$_++)+'>';"<$j"})[0..--$n]
. So now you don't have to write$x
twice.
– KGlasier
10 hours ago
Also you can save two more bytes by not using++
in($j='-'*$_++)
as you don't use$_
anywhere else.
– KGlasier
10 hours ago
1
@KGlasier Awesome - thanks for the obvious golfs! :)
– AdmBorkBork
9 hours ago
add a comment |
up vote
3
down vote
up vote
3
down vote
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.
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.
edited 9 hours ago
answered 10 hours ago
AdmBorkBork
26k364226
26k364226
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. ieparam($n)(0..$n|%{($j='-'*$_++)+'>';"<$j"})[0..--$n]
. So now you don't have to write$x
twice.
– KGlasier
10 hours ago
Also you can save two more bytes by not using++
in($j='-'*$_++)
as you don't use$_
anywhere else.
– KGlasier
10 hours ago
1
@KGlasier Awesome - thanks for the obvious golfs! :)
– AdmBorkBork
9 hours ago
add a comment |
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. ieparam($n)(0..$n|%{($j='-'*$_++)+'>';"<$j"})[0..--$n]
. So now you don't have to write$x
twice.
– KGlasier
10 hours ago
Also you can save two more bytes by not using++
in($j='-'*$_++)
as you don't use$_
anywhere else.
– KGlasier
10 hours ago
1
@KGlasier Awesome - thanks for the obvious golfs! :)
– AdmBorkBork
9 hours ago
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.– KGlasier
10 hours ago
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.– KGlasier
10 hours ago
Also you can save two more bytes by not using
++
in ($j='-'*$_++)
as you don't use $_
anywhere else.– KGlasier
10 hours ago
Also you can save two more bytes by not using
++
in ($j='-'*$_++)
as you don't use $_
anywhere else.– KGlasier
10 hours ago
1
1
@KGlasier Awesome - thanks for the obvious golfs! :)
– AdmBorkBork
9 hours ago
@KGlasier Awesome - thanks for the obvious golfs! :)
– AdmBorkBork
9 hours ago
add a comment |
up vote
3
down vote
Jelly, 15 bytes
ị⁾><;’H”-ẋƲṚ⁸¡)
Try it online!
add a comment |
up vote
3
down vote
Jelly, 15 bytes
ị⁾><;’H”-ẋƲṚ⁸¡)
Try it online!
add a comment |
up vote
3
down vote
up vote
3
down vote
Jelly, 15 bytes
ị⁾><;’H”-ẋƲṚ⁸¡)
Try it online!
Jelly, 15 bytes
ị⁾><;’H”-ẋƲṚ⁸¡)
Try it online!
answered 9 hours ago
Erik the Outgolfer
31k429102
31k429102
add a comment |
add a comment |
up vote
2
down vote
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 pattern with i/2 dashes, and increment i
); //
} //
add a comment |
up vote
2
down vote
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 pattern with i/2 dashes, and increment i
); //
} //
add a comment |
up vote
2
down vote
up vote
2
down vote
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 pattern with i/2 dashes, and increment i
); //
} //
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 pattern with i/2 dashes, and increment i
); //
} //
edited 9 hours ago
answered 10 hours ago
Olivier Grégoire
8,60711843
8,60711843
add a comment |
add a comment |
up vote
2
down vote
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!
add a comment |
up vote
2
down vote
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!
add a comment |
up vote
2
down vote
up vote
2
down vote
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!
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!
edited 9 hours ago
answered 10 hours ago
Giuseppe
16.4k31052
16.4k31052
add a comment |
add a comment |
up vote
2
down vote
V, 22 bytes
i>
<Àñäkjjé-já-ñÀGjdG
Try it online!
2
This looks like some weird scandinavian language
– Pavel
9 hours ago
add a comment |
up vote
2
down vote
V, 22 bytes
i>
<Àñäkjjé-já-ñÀGjdG
Try it online!
2
This looks like some weird scandinavian language
– Pavel
9 hours ago
add a comment |
up vote
2
down vote
up vote
2
down vote
V, 22 bytes
i>
<Àñäkjjé-já-ñÀGjdG
Try it online!
V, 22 bytes
i>
<Àñäkjjé-já-ñÀGjdG
Try it online!
answered 9 hours ago
DJMcMayhem♦
40.7k11145308
40.7k11145308
2
This looks like some weird scandinavian language
– Pavel
9 hours ago
add a comment |
2
This looks like some weird scandinavian language
– Pavel
9 hours ago
2
2
This looks like some weird scandinavian language
– Pavel
9 hours ago
This looks like some weird scandinavian language
– Pavel
9 hours ago
add a comment |
up vote
2
down vote
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.
add a comment |
up vote
2
down vote
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.
add a comment |
up vote
2
down vote
up vote
2
down vote
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.
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.
answered 6 hours ago
Neil
78.8k744175
78.8k744175
add a comment |
add a comment |
up vote
2
down vote
Japt -m
, 16 bytes
"<>"¬hUu Uz ç-)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 ["<",">"]
hUu ) #Replace the element at index U modulo 2 with:
- # The character '-'
ç # Repeated a number of times equal to
Uz # U integer divided by 2
q #Join the array to a string
1
ç
auto-casts its first parameter into a string, so you can drop the'
.
– Oliver
2 hours ago
add a comment |
up vote
2
down vote
Japt -m
, 16 bytes
"<>"¬hUu Uz ç-)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 ["<",">"]
hUu ) #Replace the element at index U modulo 2 with:
- # The character '-'
ç # Repeated a number of times equal to
Uz # U integer divided by 2
q #Join the array to a string
1
ç
auto-casts its first parameter into a string, so you can drop the'
.
– Oliver
2 hours ago
add a comment |
up vote
2
down vote
up vote
2
down vote
Japt -m
, 16 bytes
"<>"¬hUu Uz ç-)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 ["<",">"]
hUu ) #Replace the element at index U modulo 2 with:
- # The character '-'
ç # Repeated a number of times equal to
Uz # U integer divided by 2
q #Join the array to a string
Japt -m
, 16 bytes
"<>"¬hUu Uz ç-)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 ["<",">"]
hUu ) #Replace the element at index U modulo 2 with:
- # The character '-'
ç # Repeated a number of times equal to
Uz # U integer divided by 2
q #Join the array to a string
edited 31 mins ago
answered 9 hours ago
Kamil Drakari
2,861416
2,861416
1
ç
auto-casts its first parameter into a string, so you can drop the'
.
– Oliver
2 hours ago
add a comment |
1
ç
auto-casts its first parameter into a string, so you can drop the'
.
– Oliver
2 hours ago
1
1
ç
auto-casts its first parameter into a string, so you can drop the '
.– Oliver
2 hours ago
ç
auto-casts its first parameter into a string, so you can drop the '
.– Oliver
2 hours ago
add a comment |
up vote
1
down vote
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!
add a comment |
up vote
1
down vote
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!
add a comment |
up vote
1
down vote
up vote
1
down vote
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!
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!
answered 10 hours ago
Arnauld
71.3k688298
71.3k688298
add a comment |
add a comment |
up vote
1
down vote
Haskell, 51 bytes
(`take`do b<-['-'<$[1..n]|n<-[0..]];[b++">",'<':b])
Try it online!
Explanation / Ungolfed
Using do
-notation saves us a concat
, using '-'<$[1..n]
is shorter than replicate
, and finally using infix-notation allows a pointfree function with take
, undoing these would give:
f n = take n $ concat [ [b++">", '<':b] | n<-[0..], let b = replicate n '-' ]
add a comment |
up vote
1
down vote
Haskell, 51 bytes
(`take`do b<-['-'<$[1..n]|n<-[0..]];[b++">",'<':b])
Try it online!
Explanation / Ungolfed
Using do
-notation saves us a concat
, using '-'<$[1..n]
is shorter than replicate
, and finally using infix-notation allows a pointfree function with take
, undoing these would give:
f n = take n $ concat [ [b++">", '<':b] | n<-[0..], let b = replicate n '-' ]
add a comment |
up vote
1
down vote
up vote
1
down vote
Haskell, 51 bytes
(`take`do b<-['-'<$[1..n]|n<-[0..]];[b++">",'<':b])
Try it online!
Explanation / Ungolfed
Using do
-notation saves us a concat
, using '-'<$[1..n]
is shorter than replicate
, and finally using infix-notation allows a pointfree function with take
, undoing these would give:
f n = take n $ concat [ [b++">", '<':b] | n<-[0..], let b = replicate n '-' ]
Haskell, 51 bytes
(`take`do b<-['-'<$[1..n]|n<-[0..]];[b++">",'<':b])
Try it online!
Explanation / Ungolfed
Using do
-notation saves us a concat
, using '-'<$[1..n]
is shorter than replicate
, and finally using infix-notation allows a pointfree function with take
, undoing these would give:
f n = take n $ concat [ [b++">", '<':b] | n<-[0..], let b = replicate n '-' ]
edited 9 hours ago
answered 9 hours ago
BMO
11k21881
11k21881
add a comment |
add a comment |
up vote
1
down vote
Haskell, 41 bytes
(`take`g"")
g p=(p++">"):('<':p):g('-':p)
Try it online!
Plain old recursion: start with an emtpy string p
, collect p
with a right arrow, a left arrow with p
and a recursive call with p
one -
longer. Take the first n
items of this list.
add a comment |
up vote
1
down vote
Haskell, 41 bytes
(`take`g"")
g p=(p++">"):('<':p):g('-':p)
Try it online!
Plain old recursion: start with an emtpy string p
, collect p
with a right arrow, a left arrow with p
and a recursive call with p
one -
longer. Take the first n
items of this list.
add a comment |
up vote
1
down vote
up vote
1
down vote
Haskell, 41 bytes
(`take`g"")
g p=(p++">"):('<':p):g('-':p)
Try it online!
Plain old recursion: start with an emtpy string p
, collect p
with a right arrow, a left arrow with p
and a recursive call with p
one -
longer. Take the first n
items of this list.
Haskell, 41 bytes
(`take`g"")
g p=(p++">"):('<':p):g('-':p)
Try it online!
Plain old recursion: start with an emtpy string p
, collect p
with a right arrow, a left arrow with p
and a recursive call with p
one -
longer. Take the first n
items of this list.
edited 9 hours ago
answered 9 hours ago
nimi
31.1k31985
31.1k31985
add a comment |
add a comment |
up vote
1
down vote
Powershell, 51 bytes
param($n)0..$n|%{'-'*$_+'>';'<'+'-'*$_}|?{$n---gt0}
add a comment |
up vote
1
down vote
Powershell, 51 bytes
param($n)0..$n|%{'-'*$_+'>';'<'+'-'*$_}|?{$n---gt0}
add a comment |
up vote
1
down vote
up vote
1
down vote
Powershell, 51 bytes
param($n)0..$n|%{'-'*$_+'>';'<'+'-'*$_}|?{$n---gt0}
Powershell, 51 bytes
param($n)0..$n|%{'-'*$_+'>';'<'+'-'*$_}|?{$n---gt0}
answered 9 hours ago
mazzy
1,985314
1,985314
add a comment |
add a comment |
up vote
1
down vote
05AB1E, 23 bytes
FN2%D"><"è'-N2÷∍«s_iR},
Try it online!
First time using 05AB1E or any other golfing language for that matter. Any ideas welcome.
add a comment |
up vote
1
down vote
05AB1E, 23 bytes
FN2%D"><"è'-N2÷∍«s_iR},
Try it online!
First time using 05AB1E or any other golfing language for that matter. Any ideas welcome.
add a comment |
up vote
1
down vote
up vote
1
down vote
05AB1E, 23 bytes
FN2%D"><"è'-N2÷∍«s_iR},
Try it online!
First time using 05AB1E or any other golfing language for that matter. Any ideas welcome.
05AB1E, 23 bytes
FN2%D"><"è'-N2÷∍«s_iR},
Try it online!
First time using 05AB1E or any other golfing language for that matter. Any ideas welcome.
answered 7 hours ago
nedla2004
3211310
3211310
add a comment |
add a comment |
up vote
1
down vote
Java 123 bytes
n->{String l="",r="";for(int c=0;c<n;c++)System.out.println(c%2==0?r=c==0?">":c==1?"<":"-"+r:(l+=c==0?">":c==1?"<":"-"));}
add a comment |
up vote
1
down vote
Java 123 bytes
n->{String l="",r="";for(int c=0;c<n;c++)System.out.println(c%2==0?r=c==0?">":c==1?"<":"-"+r:(l+=c==0?">":c==1?"<":"-"));}
add a comment |
up vote
1
down vote
up vote
1
down vote
Java 123 bytes
n->{String l="",r="";for(int c=0;c<n;c++)System.out.println(c%2==0?r=c==0?">":c==1?"<":"-"+r:(l+=c==0?">":c==1?"<":"-"));}
Java 123 bytes
n->{String l="",r="";for(int c=0;c<n;c++)System.out.println(c%2==0?r=c==0?">":c==1?"<":"-"+r:(l+=c==0?">":c==1?"<":"-"));}
answered 5 hours ago
isaace
1714
1714
add a comment |
add a comment |
up vote
1
down vote
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.
add a comment |
up vote
1
down vote
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.
add a comment |
up vote
1
down vote
up vote
1
down vote
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.
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.
answered 5 hours ago
Οurous
6,18311032
6,18311032
add a comment |
add a comment |
up vote
1
down vote
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
add a comment |
up vote
1
down vote
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
add a comment |
up vote
1
down vote
up vote
1
down vote
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
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
answered 5 hours ago
Felix Palmen
3,271525
3,271525
add a comment |
add a comment |
up vote
1
down vote
Perl 5, 44 bytes
map{$_/=2;say'<'x/./,'-'x$_,'>'x!$&}0..<>-1
Try it online!
add a comment |
up vote
1
down vote
Perl 5, 44 bytes
map{$_/=2;say'<'x/./,'-'x$_,'>'x!$&}0..<>-1
Try it online!
add a comment |
up vote
1
down vote
up vote
1
down vote
Perl 5, 44 bytes
map{$_/=2;say'<'x/./,'-'x$_,'>'x!$&}0..<>-1
Try it online!
Perl 5, 44 bytes
map{$_/=2;say'<'x/./,'-'x$_,'>'x!$&}0..<>-1
Try it online!
answered 4 hours ago
Xcali
5,059520
5,059520
add a comment |
add a comment |
up vote
1
down vote
Japt -m
, 16 15 13 bytes
g"><" iUUz ç-
Test it online
add a comment |
up vote
1
down vote
Japt -m
, 16 15 13 bytes
g"><" iUUz ç-
Test it online
add a comment |
up vote
1
down vote
up vote
1
down vote
Japt -m
, 16 15 13 bytes
g"><" iUUz ç-
Test it online
Japt -m
, 16 15 13 bytes
g"><" iUUz ç-
Test it online
edited 2 hours ago
answered 7 hours ago
Oliver
4,6901831
4,6901831
add a comment |
add a comment |
up vote
0
down vote
Perl 6, 39 bytes
{map {'<'x$_%2~'-'x$_/2~'>'x$_%%2},^$_}
Try it online!
Anonymous code block that returns a list of lines.
add a comment |
up vote
0
down vote
Perl 6, 39 bytes
{map {'<'x$_%2~'-'x$_/2~'>'x$_%%2},^$_}
Try it online!
Anonymous code block that returns a list of lines.
add a comment |
up vote
0
down vote
up vote
0
down vote
Perl 6, 39 bytes
{map {'<'x$_%2~'-'x$_/2~'>'x$_%%2},^$_}
Try it online!
Anonymous code block that returns a list of lines.
Perl 6, 39 bytes
{map {'<'x$_%2~'-'x$_/2~'>'x$_%%2},^$_}
Try it online!
Anonymous code block that returns a list of lines.
answered 3 hours ago
Jo King
20.3k245107
20.3k245107
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f177454%2fdraw-some-expanding-arrows%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Related.
– AdmBorkBork
10 hours ago
Can we have spaces before/after each line?
– Olivier Grégoire
10 hours ago
@OlivierGrégoire Yes, trailing whitespace is ok.
– Pavel
10 hours ago
And heading whitespace?
– Olivier Grégoire
10 hours ago
@OlivierGrégoire Yeah, that's fine.
– Pavel
10 hours ago