Draw some expanding arrows
up vote
21
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
21
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
2
Related.
– AdmBorkBork
Dec 12 at 16:23
Can we have spaces before/after each line?
– Olivier Grégoire
Dec 12 at 16:54
@OlivierGrégoire Yes, trailing whitespace is ok.
– Pavel
Dec 12 at 16:55
And heading whitespace?
– Olivier Grégoire
Dec 12 at 16:58
@OlivierGrégoire Yeah, that's fine.
– Pavel
Dec 12 at 17:00
add a comment |
up vote
21
down vote
favorite
up vote
21
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 Dec 12 at 15:56
Pavel
4,80013389
4,80013389
2
Related.
– AdmBorkBork
Dec 12 at 16:23
Can we have spaces before/after each line?
– Olivier Grégoire
Dec 12 at 16:54
@OlivierGrégoire Yes, trailing whitespace is ok.
– Pavel
Dec 12 at 16:55
And heading whitespace?
– Olivier Grégoire
Dec 12 at 16:58
@OlivierGrégoire Yeah, that's fine.
– Pavel
Dec 12 at 17:00
add a comment |
2
Related.
– AdmBorkBork
Dec 12 at 16:23
Can we have spaces before/after each line?
– Olivier Grégoire
Dec 12 at 16:54
@OlivierGrégoire Yes, trailing whitespace is ok.
– Pavel
Dec 12 at 16:55
And heading whitespace?
– Olivier Grégoire
Dec 12 at 16:58
@OlivierGrégoire Yeah, that's fine.
– Pavel
Dec 12 at 17:00
2
2
Related.
– AdmBorkBork
Dec 12 at 16:23
Related.
– AdmBorkBork
Dec 12 at 16:23
Can we have spaces before/after each line?
– Olivier Grégoire
Dec 12 at 16:54
Can we have spaces before/after each line?
– Olivier Grégoire
Dec 12 at 16:54
@OlivierGrégoire Yes, trailing whitespace is ok.
– Pavel
Dec 12 at 16:55
@OlivierGrégoire Yes, trailing whitespace is ok.
– Pavel
Dec 12 at 16:55
And heading whitespace?
– Olivier Grégoire
Dec 12 at 16:58
And heading whitespace?
– Olivier Grégoire
Dec 12 at 16:58
@OlivierGrégoire Yeah, that's fine.
– Pavel
Dec 12 at 17:00
@OlivierGrégoire Yeah, that's fine.
– Pavel
Dec 12 at 17:00
add a comment |
38 Answers
38
active
oldest
votes
1 2
next
up vote
6
down vote
accepted
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
Dec 12 at 16:03
↔
is the "reverse horizontally" built-in (also swapping>
&<
), sadly no arrow built-ins :p
– dzaima
Dec 12 at 16:04
add a comment |
up vote
8
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
Dec 12 at 16:40
you can also get rid ofa
entirely by indexing over0...(n-1)
instead: Try it online!
– Giuseppe
Dec 12 at 16:44
I'm an idiot... thanks ! :D
– digEmAll
Dec 12 at 17:17
@Giuseppe :also I just noticed the deleted question of Robert S. I can use rep instead of strrep and save 3 bytes...(facepalm)
– digEmAll
Dec 12 at 17:21
add a comment |
up vote
8
down vote
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.
1
A weird change to save a byte.
– xnor
Dec 13 at 5:44
add a comment |
up vote
7
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 "%s" in the pattern with i/2 dashes, and increment i
); //
} //
Consider removing static reference to System.out
– candied_orange
Dec 15 at 18:11
@candied_orange That's not self-contained.
– Olivier Grégoire
Dec 15 at 18:32
How about done like this?
– candied_orange
Dec 15 at 18:52
@candied_orange It's the same: the imports are required in the count.
– Olivier Grégoire
Dec 15 at 19:38
Why doesn'timport java.util.function.*;
count?
– candied_orange
Dec 15 at 19:44
|
show 2 more comments
up vote
6
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
6
down vote
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!
3
Your arrows have too many dashes; only every other one should lengthen by a dash.
– xnor
Dec 13 at 2:35
1
54 bytes
– tsh
Dec 13 at 5:23
54 bytes with the arrows pointing the right way
– Jo King
Dec 13 at 9:52
add a comment |
up vote
5
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
5
down vote
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
New contributor
1
Welcome to PPCG! You can remove the brackets by putting the string after the number, use~i
instead ofi+1
and use//
to integer divide, assuming you're using Python 3. 53 bytes
– Jo King
Dec 13 at 9:45
1
I've linked the updated solution in my previous comment. If you like, you can use the auto-formatter in the TIO link to help create your answer
– Jo King
Dec 13 at 9:54
add a comment |
up vote
5
down vote
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
add a comment |
up vote
5
down vote
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 ('-':) "" ]
1
You can shorten the part afterdo
tob<-iterate('-':)""
.
– xnor
Dec 13 at 5:33
add a comment |
up vote
5
down vote
Japt -m
, 16 15 13 bytes
g"><" iUUz ç-
Test it online
Explanation:
-m // Map the program through [0...Input); U becomes the item
g"><" iUUz ç-
"><" // Literal "><"
g // Get the char at index U (with wrapping)
i // Insert:
U // At index U (with wrapping)
ç- // "-" repeated:
Uz // U/2 times
add a comment |
up vote
4
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
Dec 12 at 17:00
Also you can save two more bytes by not using++
in($j='-'*$_++)
as you don't use$_
anywhere else.
– KGlasier
Dec 12 at 17:03
1
@KGlasier Awesome - thanks for the obvious golfs! :)
– AdmBorkBork
Dec 12 at 17:16
add a comment |
up vote
4
down vote
Jelly, 15 bytes
ị⁾><;’H”-ẋƲṚ⁸¡)
Try it online!
-1 byte using tie: TIO.
– HyperNeutrino
Dec 14 at 14:29
add a comment |
up vote
4
down vote
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
How does theif/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.)
– Kevin Cruijssen
Dec 13 at 10:20
1
@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
– Jo King
Dec 13 at 10:30
@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}
.
– maxb
Dec 13 at 10:34
@JoKing I'll add a TODO to fix the docs for the slicing operators.
– maxb
Dec 13 at 10:35
1
15 bytes using @KevinCruijssen's solution
– Jo King
Dec 13 at 10:46
|
show 3 more comments
up vote
4
down vote
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
1
ç
auto-casts its first parameter into a string, so you can drop the'
.
– Oliver
Dec 13 at 0:21
1
You don't need theu
method thanks to index wrapping so this can be 14 bytes.
– Shaggy
Dec 13 at 8:13
add a comment |
up vote
3
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
3
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
3
down vote
V, 22 bytes
i>
<Àñäkjjé-já-ñÀGjdG
Try it online!
5
This looks like some weird scandinavian language
– Pavel
Dec 12 at 18:02
add a comment |
up vote
3
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
3
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
3
down vote
JavaScript, 49 bytes
f=n=>--n?f(n,l='')+(n%2?`
<`+l:`
${l+='-'}>`):'>'
Try it online!
Wow, pretty cool
– Levitator Imbalance
Dec 14 at 10:41
...but it throws on10000
, meanwhile my ES6 solution is still works :D Anyway, your solution is very cool)
– Levitator Imbalance
Dec 14 at 10:53
add a comment |
up vote
2
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
2
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
2
down vote
K (ngn/k), 31 29 bytes
{"<->"x#2,x{(1=*x)_1,2-|x}}
Try it online!
first we generate lists with 0 instead of "<"
, 1 instead of "-"
, and 2 instead of ">"
:
{
}
function with argument x
x{
...}
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
I would like to ask for an explanation (I haven't started learning K yet, I don't know which version to start with...)
– Galen Ivanov
Dec 13 at 12:14
1
@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?
– ngn
Dec 13 at 12:44
Thank you, I'm already there
– Galen Ivanov
Dec 13 at 12:49
add a comment |
up vote
2
down vote
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
1
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.
– Kevin Cruijssen
Dec 13 at 8:54
1
@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.
– nedla2004
Dec 13 at 23:09
I've posted my answer in that case. :)
– Kevin Cruijssen
Dec 14 at 8:31
add a comment |
up vote
2
down vote
ES6, 96 82 79 70 bytes
Try it online! (Thanks to @Oliver)
n=>[...Array(n)].map((_,i)=>(i%2?"<":"")+"-".repeat(i/2)+(i%2?"":">"))
New contributor
1
Welcome to PPCG! By default, taking input as a variable is disallowed; you have to either make it a function (just stick ai=>
in front of your code!) or from a command-line argument or STDIN or something.
– HyperNeutrino
Dec 14 at 14:40
@HyperNeutrino okay, edited answer. However, the most voted answer contains only the body of the function, but ok. Anyway I'm outsider)
– Levitator Imbalance
Dec 14 at 15:09
Can you link it? I don't think any of them are invalid, at least not the top few.
– HyperNeutrino
Dec 14 at 15:16
1
A few more bytes: Try it online
– Oliver
Dec 14 at 16:15
1
A few more bytes if you re-arrange that last ternary operator and remove the center parenthesis: Try it online
– Oliver
Dec 14 at 16:59
|
show 7 more comments
up vote
2
down vote
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!
1
-1 for removing a space
– NK1406
Dec 15 at 18:28
@NK1406 Thank you! I didn't know this is valid.
– Galen Ivanov
Dec 15 at 19:01
add a comment |
up vote
2
down vote
C (gcc), 127 95 + 26 = 121 bytes
i,j;f(x){for(i=0;i<x;putchar(10),i+=2){for(j=0;E;printf(">n%c",x-i-1?60:9);for(j=0;x-i-1&&E;}}
Try it online!
Compile with -DE=j<i/2;++j)putchar(45)
-6 bytes from Logern
Yay mismatched parentheses!
Ungolfed:
void f(int x) {
for (int i = 0; i < x; i += 2) {
for (int j = 0; j < i/2; ++j) {
printf("-");
}
printf(">n");
if (x - i - 1) { // Test for last loop: only print <-- if x is even
printf("<");
for (int j = 0; j < i/2; ++j) {
printf("-");
}
}
else {
printf("t"); // This is the 9 in the x-i-1?60:9
}
printf("n");
}
}
Try it online!
1
121 bytes with a -D compiler flag instead of #define - Try it online!
– Logern
Dec 14 at 17:31
Another -3 bytes by taking out the i=0 like this
– NK1406
Dec 15 at 18:19
@NK1406 Functions have to be reusable, that edit would break this rule. Try it online!
– pizzapants184
2 days ago
Suggestx+~i
instead ofx-i-1
– ceilingcat
2 days ago
@pizzapants184 Sorry, didn't see that!
– NK1406
2 days ago
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
Perl 5, 44 bytes
map{$_/=2;say'<'x/./,'-'x$_,'>'x!$&}0..<>-1
Try it online!
add a comment |
1 2
next
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "200"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
38 Answers
38
active
oldest
votes
38 Answers
38
active
oldest
votes
active
oldest
votes
active
oldest
votes
1 2
next
up vote
6
down vote
accepted
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
Dec 12 at 16:03
↔
is the "reverse horizontally" built-in (also swapping>
&<
), sadly no arrow built-ins :p
– dzaima
Dec 12 at 16:04
add a comment |
up vote
6
down vote
accepted
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
Dec 12 at 16:03
↔
is the "reverse horizontally" built-in (also swapping>
&<
), sadly no arrow built-ins :p
– dzaima
Dec 12 at 16:04
add a comment |
up vote
6
down vote
accepted
up vote
6
down vote
accepted
Canvas, 10 bytes
⇵-×<n¹[↔}]
Try it here!
Canvas, 10 bytes
⇵-×<n¹[↔}]
Try it here!
answered Dec 12 at 16:01
dzaima
14.4k21754
14.4k21754
I don't know any Canvas, but is that an arrow-drawing builtin I see?↔
kinda looks like it!
– Pavel
Dec 12 at 16:03
↔
is the "reverse horizontally" built-in (also swapping>
&<
), sadly no arrow built-ins :p
– dzaima
Dec 12 at 16:04
add a comment |
I don't know any Canvas, but is that an arrow-drawing builtin I see?↔
kinda looks like it!
– Pavel
Dec 12 at 16:03
↔
is the "reverse horizontally" built-in (also swapping>
&<
), sadly no arrow built-ins :p
– dzaima
Dec 12 at 16:04
I don't know any Canvas, but is that an arrow-drawing builtin I see?
↔
kinda looks like it!– Pavel
Dec 12 at 16:03
I don't know any Canvas, but is that an arrow-drawing builtin I see?
↔
kinda looks like it!– Pavel
Dec 12 at 16:03
↔
is the "reverse horizontally" built-in (also swapping >
& <
), sadly no arrow built-ins :p– dzaima
Dec 12 at 16:04
↔
is the "reverse horizontally" built-in (also swapping >
& <
), sadly no arrow built-ins :p– dzaima
Dec 12 at 16:04
add a comment |
up vote
8
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
Dec 12 at 16:40
you can also get rid ofa
entirely by indexing over0...(n-1)
instead: Try it online!
– Giuseppe
Dec 12 at 16:44
I'm an idiot... thanks ! :D
– digEmAll
Dec 12 at 17:17
@Giuseppe :also I just noticed the deleted question of Robert S. I can use rep instead of strrep and save 3 bytes...(facepalm)
– digEmAll
Dec 12 at 17:21
add a comment |
up vote
8
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
Dec 12 at 16:40
you can also get rid ofa
entirely by indexing over0...(n-1)
instead: Try it online!
– Giuseppe
Dec 12 at 16:44
I'm an idiot... thanks ! :D
– digEmAll
Dec 12 at 17:17
@Giuseppe :also I just noticed the deleted question of Robert S. I can use rep instead of strrep and save 3 bytes...(facepalm)
– digEmAll
Dec 12 at 17:21
add a comment |
up vote
8
down vote
up vote
8
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 Dec 12 at 17:18
answered Dec 12 at 16:36
digEmAll
2,43148
2,43148
strrep
coerces its second argument tointeger
so you can use/
in place of%/%
– Giuseppe
Dec 12 at 16:40
you can also get rid ofa
entirely by indexing over0...(n-1)
instead: Try it online!
– Giuseppe
Dec 12 at 16:44
I'm an idiot... thanks ! :D
– digEmAll
Dec 12 at 17:17
@Giuseppe :also I just noticed the deleted question of Robert S. I can use rep instead of strrep and save 3 bytes...(facepalm)
– digEmAll
Dec 12 at 17:21
add a comment |
strrep
coerces its second argument tointeger
so you can use/
in place of%/%
– Giuseppe
Dec 12 at 16:40
you can also get rid ofa
entirely by indexing over0...(n-1)
instead: Try it online!
– Giuseppe
Dec 12 at 16:44
I'm an idiot... thanks ! :D
– digEmAll
Dec 12 at 17:17
@Giuseppe :also I just noticed the deleted question of Robert S. I can use rep instead of strrep and save 3 bytes...(facepalm)
– digEmAll
Dec 12 at 17:21
strrep
coerces its second argument to integer
so you can use /
in place of %/%
– Giuseppe
Dec 12 at 16:40
strrep
coerces its second argument to integer
so you can use /
in place of %/%
– Giuseppe
Dec 12 at 16:40
you can also get rid of
a
entirely by indexing over 0...(n-1)
instead: Try it online!– Giuseppe
Dec 12 at 16:44
you can also get rid of
a
entirely by indexing over 0...(n-1)
instead: Try it online!– Giuseppe
Dec 12 at 16:44
I'm an idiot... thanks ! :D
– digEmAll
Dec 12 at 17:17
I'm an idiot... thanks ! :D
– digEmAll
Dec 12 at 17:17
@Giuseppe :also I just noticed the deleted question of Robert S. I can use rep instead of strrep and save 3 bytes...(facepalm)
– digEmAll
Dec 12 at 17:21
@Giuseppe :also I just noticed the deleted question of Robert S. I can use rep instead of strrep and save 3 bytes...(facepalm)
– digEmAll
Dec 12 at 17:21
add a comment |
up vote
8
down vote
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.
1
A weird change to save a byte.
– xnor
Dec 13 at 5:44
add a comment |
up vote
8
down vote
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.
1
A weird change to save a byte.
– xnor
Dec 13 at 5:44
add a comment |
up vote
8
down vote
up vote
8
down vote
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.
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.
edited Dec 13 at 18:05
answered Dec 12 at 17:33
nimi
31.1k31985
31.1k31985
1
A weird change to save a byte.
– xnor
Dec 13 at 5:44
add a comment |
1
A weird change to save a byte.
– xnor
Dec 13 at 5:44
1
1
A weird change to save a byte.
– xnor
Dec 13 at 5:44
A weird change to save a byte.
– xnor
Dec 13 at 5:44
add a comment |
up vote
7
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 "%s" in the pattern with i/2 dashes, and increment i
); //
} //
Consider removing static reference to System.out
– candied_orange
Dec 15 at 18:11
@candied_orange That's not self-contained.
– Olivier Grégoire
Dec 15 at 18:32
How about done like this?
– candied_orange
Dec 15 at 18:52
@candied_orange It's the same: the imports are required in the count.
– Olivier Grégoire
Dec 15 at 19:38
Why doesn'timport java.util.function.*;
count?
– candied_orange
Dec 15 at 19:44
|
show 2 more comments
up vote
7
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 "%s" in the pattern with i/2 dashes, and increment i
); //
} //
Consider removing static reference to System.out
– candied_orange
Dec 15 at 18:11
@candied_orange That's not self-contained.
– Olivier Grégoire
Dec 15 at 18:32
How about done like this?
– candied_orange
Dec 15 at 18:52
@candied_orange It's the same: the imports are required in the count.
– Olivier Grégoire
Dec 15 at 19:38
Why doesn'timport java.util.function.*;
count?
– candied_orange
Dec 15 at 19:44
|
show 2 more comments
up vote
7
down vote
up vote
7
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 "%s" in 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 "%s" in the pattern with i/2 dashes, and increment i
); //
} //
edited Dec 13 at 11:01
answered Dec 12 at 16:41
Olivier Grégoire
8,74711843
8,74711843
Consider removing static reference to System.out
– candied_orange
Dec 15 at 18:11
@candied_orange That's not self-contained.
– Olivier Grégoire
Dec 15 at 18:32
How about done like this?
– candied_orange
Dec 15 at 18:52
@candied_orange It's the same: the imports are required in the count.
– Olivier Grégoire
Dec 15 at 19:38
Why doesn'timport java.util.function.*;
count?
– candied_orange
Dec 15 at 19:44
|
show 2 more comments
Consider removing static reference to System.out
– candied_orange
Dec 15 at 18:11
@candied_orange That's not self-contained.
– Olivier Grégoire
Dec 15 at 18:32
How about done like this?
– candied_orange
Dec 15 at 18:52
@candied_orange It's the same: the imports are required in the count.
– Olivier Grégoire
Dec 15 at 19:38
Why doesn'timport java.util.function.*;
count?
– candied_orange
Dec 15 at 19:44
Consider removing static reference to System.out
– candied_orange
Dec 15 at 18:11
Consider removing static reference to System.out
– candied_orange
Dec 15 at 18:11
@candied_orange That's not self-contained.
– Olivier Grégoire
Dec 15 at 18:32
@candied_orange That's not self-contained.
– Olivier Grégoire
Dec 15 at 18:32
How about done like this?
– candied_orange
Dec 15 at 18:52
How about done like this?
– candied_orange
Dec 15 at 18:52
@candied_orange It's the same: the imports are required in the count.
– Olivier Grégoire
Dec 15 at 19:38
@candied_orange It's the same: the imports are required in the count.
– Olivier Grégoire
Dec 15 at 19:38
Why doesn't
import java.util.function.*;
count?– candied_orange
Dec 15 at 19:44
Why doesn't
import java.util.function.*;
count?– candied_orange
Dec 15 at 19:44
|
show 2 more comments
up vote
6
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
6
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
6
down vote
up vote
6
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 Dec 12 at 16:53
Felix Palmen
3,331525
3,331525
add a comment |
add a comment |
up vote
6
down vote
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!
3
Your arrows have too many dashes; only every other one should lengthen by a dash.
– xnor
Dec 13 at 2:35
1
54 bytes
– tsh
Dec 13 at 5:23
54 bytes with the arrows pointing the right way
– Jo King
Dec 13 at 9:52
add a comment |
up vote
6
down vote
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!
3
Your arrows have too many dashes; only every other one should lengthen by a dash.
– xnor
Dec 13 at 2:35
1
54 bytes
– tsh
Dec 13 at 5:23
54 bytes with the arrows pointing the right way
– Jo King
Dec 13 at 9:52
add a comment |
up vote
6
down vote
up vote
6
down vote
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!
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!
edited Dec 13 at 17:25
answered Dec 12 at 16:14
ovs
18.7k21059
18.7k21059
3
Your arrows have too many dashes; only every other one should lengthen by a dash.
– xnor
Dec 13 at 2:35
1
54 bytes
– tsh
Dec 13 at 5:23
54 bytes with the arrows pointing the right way
– Jo King
Dec 13 at 9:52
add a comment |
3
Your arrows have too many dashes; only every other one should lengthen by a dash.
– xnor
Dec 13 at 2:35
1
54 bytes
– tsh
Dec 13 at 5:23
54 bytes with the arrows pointing the right way
– Jo King
Dec 13 at 9:52
3
3
Your arrows have too many dashes; only every other one should lengthen by a dash.
– xnor
Dec 13 at 2:35
Your arrows have too many dashes; only every other one should lengthen by a dash.
– xnor
Dec 13 at 2:35
1
1
54 bytes
– tsh
Dec 13 at 5:23
54 bytes
– tsh
Dec 13 at 5:23
54 bytes with the arrows pointing the right way
– Jo King
Dec 13 at 9:52
54 bytes with the arrows pointing the right way
– Jo King
Dec 13 at 9:52
add a comment |
up vote
5
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
5
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
5
down vote
up vote
5
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 Dec 12 at 16:16
Sok
3,509722
3,509722
add a comment |
add a comment |
up vote
5
down vote
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
New contributor
1
Welcome to PPCG! You can remove the brackets by putting the string after the number, use~i
instead ofi+1
and use//
to integer divide, assuming you're using Python 3. 53 bytes
– Jo King
Dec 13 at 9:45
1
I've linked the updated solution in my previous comment. If you like, you can use the auto-formatter in the TIO link to help create your answer
– Jo King
Dec 13 at 9:54
add a comment |
up vote
5
down vote
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
New contributor
1
Welcome to PPCG! You can remove the brackets by putting the string after the number, use~i
instead ofi+1
and use//
to integer divide, assuming you're using Python 3. 53 bytes
– Jo King
Dec 13 at 9:45
1
I've linked the updated solution in my previous comment. If you like, you can use the auto-formatter in the TIO link to help create your answer
– Jo King
Dec 13 at 9:54
add a comment |
up vote
5
down vote
up vote
5
down vote
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
New contributor
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
New contributor
edited Dec 13 at 9:54
New contributor
answered Dec 13 at 9:28
van der Zon Stef
1513
1513
New contributor
New contributor
1
Welcome to PPCG! You can remove the brackets by putting the string after the number, use~i
instead ofi+1
and use//
to integer divide, assuming you're using Python 3. 53 bytes
– Jo King
Dec 13 at 9:45
1
I've linked the updated solution in my previous comment. If you like, you can use the auto-formatter in the TIO link to help create your answer
– Jo King
Dec 13 at 9:54
add a comment |
1
Welcome to PPCG! You can remove the brackets by putting the string after the number, use~i
instead ofi+1
and use//
to integer divide, assuming you're using Python 3. 53 bytes
– Jo King
Dec 13 at 9:45
1
I've linked the updated solution in my previous comment. If you like, you can use the auto-formatter in the TIO link to help create your answer
– Jo King
Dec 13 at 9:54
1
1
Welcome to PPCG! You can remove the brackets by putting the string after the number, use
~i
instead of i+1
and use //
to integer divide, assuming you're using Python 3. 53 bytes– Jo King
Dec 13 at 9:45
Welcome to PPCG! You can remove the brackets by putting the string after the number, use
~i
instead of i+1
and use //
to integer divide, assuming you're using Python 3. 53 bytes– Jo King
Dec 13 at 9:45
1
1
I've linked the updated solution in my previous comment. If you like, you can use the auto-formatter in the TIO link to help create your answer
– Jo King
Dec 13 at 9:54
I've linked the updated solution in my previous comment. If you like, you can use the auto-formatter in the TIO link to help create your answer
– Jo King
Dec 13 at 9:54
add a comment |
up vote
5
down vote
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
add a comment |
up vote
5
down vote
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
add a comment |
up vote
5
down vote
up vote
5
down vote
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
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
edited Dec 13 at 11:12
answered Dec 13 at 10:48
user202729
13.9k12551
13.9k12551
add a comment |
add a comment |
up vote
5
down vote
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 ('-':) "" ]
1
You can shorten the part afterdo
tob<-iterate('-':)""
.
– xnor
Dec 13 at 5:33
add a comment |
up vote
5
down vote
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 ('-':) "" ]
1
You can shorten the part afterdo
tob<-iterate('-':)""
.
– xnor
Dec 13 at 5:33
add a comment |
up vote
5
down vote
up vote
5
down vote
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 ('-':) "" ]
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 ('-':) "" ]
edited Dec 13 at 14:04
answered Dec 12 at 17:22
BMO
11.2k22084
11.2k22084
1
You can shorten the part afterdo
tob<-iterate('-':)""
.
– xnor
Dec 13 at 5:33
add a comment |
1
You can shorten the part afterdo
tob<-iterate('-':)""
.
– xnor
Dec 13 at 5:33
1
1
You can shorten the part after
do
to b<-iterate('-':)""
.– xnor
Dec 13 at 5:33
You can shorten the part after
do
to b<-iterate('-':)""
.– xnor
Dec 13 at 5:33
add a comment |
up vote
5
down vote
Japt -m
, 16 15 13 bytes
g"><" iUUz ç-
Test it online
Explanation:
-m // Map the program through [0...Input); U becomes the item
g"><" iUUz ç-
"><" // Literal "><"
g // Get the char at index U (with wrapping)
i // Insert:
U // At index U (with wrapping)
ç- // "-" repeated:
Uz // U/2 times
add a comment |
up vote
5
down vote
Japt -m
, 16 15 13 bytes
g"><" iUUz ç-
Test it online
Explanation:
-m // Map the program through [0...Input); U becomes the item
g"><" iUUz ç-
"><" // Literal "><"
g // Get the char at index U (with wrapping)
i // Insert:
U // At index U (with wrapping)
ç- // "-" repeated:
Uz // U/2 times
add a comment |
up vote
5
down vote
up vote
5
down vote
Japt -m
, 16 15 13 bytes
g"><" iUUz ç-
Test it online
Explanation:
-m // Map the program through [0...Input); U becomes the item
g"><" iUUz ç-
"><" // Literal "><"
g // Get the char at index U (with wrapping)
i // Insert:
U // At index U (with wrapping)
ç- // "-" repeated:
Uz // U/2 times
Japt -m
, 16 15 13 bytes
g"><" iUUz ç-
Test it online
Explanation:
-m // Map the program through [0...Input); U becomes the item
g"><" iUUz ç-
"><" // Literal "><"
g // Get the char at index U (with wrapping)
i // Insert:
U // At index U (with wrapping)
ç- // "-" repeated:
Uz // U/2 times
edited Dec 14 at 15:24
answered Dec 12 at 19:49
Oliver
4,7301831
4,7301831
add a comment |
add a comment |
up vote
4
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
Dec 12 at 17:00
Also you can save two more bytes by not using++
in($j='-'*$_++)
as you don't use$_
anywhere else.
– KGlasier
Dec 12 at 17:03
1
@KGlasier Awesome - thanks for the obvious golfs! :)
– AdmBorkBork
Dec 12 at 17:16
add a comment |
up vote
4
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
Dec 12 at 17:00
Also you can save two more bytes by not using++
in($j='-'*$_++)
as you don't use$_
anywhere else.
– KGlasier
Dec 12 at 17:03
1
@KGlasier Awesome - thanks for the obvious golfs! :)
– AdmBorkBork
Dec 12 at 17:16
add a comment |
up vote
4
down vote
up vote
4
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 Dec 12 at 17:16
answered Dec 12 at 16:34
AdmBorkBork
26.1k364226
26.1k364226
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
Dec 12 at 17:00
Also you can save two more bytes by not using++
in($j='-'*$_++)
as you don't use$_
anywhere else.
– KGlasier
Dec 12 at 17:03
1
@KGlasier Awesome - thanks for the obvious golfs! :)
– AdmBorkBork
Dec 12 at 17:16
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
Dec 12 at 17:00
Also you can save two more bytes by not using++
in($j='-'*$_++)
as you don't use$_
anywhere else.
– KGlasier
Dec 12 at 17:03
1
@KGlasier Awesome - thanks for the obvious golfs! :)
– AdmBorkBork
Dec 12 at 17:16
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
Dec 12 at 17:00
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
Dec 12 at 17:00
Also you can save two more bytes by not using
++
in ($j='-'*$_++)
as you don't use $_
anywhere else.– KGlasier
Dec 12 at 17:03
Also you can save two more bytes by not using
++
in ($j='-'*$_++)
as you don't use $_
anywhere else.– KGlasier
Dec 12 at 17:03
1
1
@KGlasier Awesome - thanks for the obvious golfs! :)
– AdmBorkBork
Dec 12 at 17:16
@KGlasier Awesome - thanks for the obvious golfs! :)
– AdmBorkBork
Dec 12 at 17:16
add a comment |
up vote
4
down vote
Jelly, 15 bytes
ị⁾><;’H”-ẋƲṚ⁸¡)
Try it online!
-1 byte using tie: TIO.
– HyperNeutrino
Dec 14 at 14:29
add a comment |
up vote
4
down vote
Jelly, 15 bytes
ị⁾><;’H”-ẋƲṚ⁸¡)
Try it online!
-1 byte using tie: TIO.
– HyperNeutrino
Dec 14 at 14:29
add a comment |
up vote
4
down vote
up vote
4
down vote
Jelly, 15 bytes
ị⁾><;’H”-ẋƲṚ⁸¡)
Try it online!
Jelly, 15 bytes
ị⁾><;’H”-ẋƲṚ⁸¡)
Try it online!
answered Dec 12 at 17:17
Erik the Outgolfer
31.2k429102
31.2k429102
-1 byte using tie: TIO.
– HyperNeutrino
Dec 14 at 14:29
add a comment |
-1 byte using tie: TIO.
– HyperNeutrino
Dec 14 at 14:29
-1 byte using tie: TIO.
– HyperNeutrino
Dec 14 at 14:29
-1 byte using tie: TIO.
– HyperNeutrino
Dec 14 at 14:29
add a comment |
up vote
4
down vote
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
How does theif/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.)
– Kevin Cruijssen
Dec 13 at 10:20
1
@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
– Jo King
Dec 13 at 10:30
@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}
.
– maxb
Dec 13 at 10:34
@JoKing I'll add a TODO to fix the docs for the slicing operators.
– maxb
Dec 13 at 10:35
1
15 bytes using @KevinCruijssen's solution
– Jo King
Dec 13 at 10:46
|
show 3 more comments
up vote
4
down vote
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
How does theif/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.)
– Kevin Cruijssen
Dec 13 at 10:20
1
@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
– Jo King
Dec 13 at 10:30
@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}
.
– maxb
Dec 13 at 10:34
@JoKing I'll add a TODO to fix the docs for the slicing operators.
– maxb
Dec 13 at 10:35
1
15 bytes using @KevinCruijssen's solution
– Jo King
Dec 13 at 10:46
|
show 3 more comments
up vote
4
down vote
up vote
4
down vote
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
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
edited Dec 13 at 11:47
answered Dec 13 at 10:08
maxb
2,6331927
2,6331927
How does theif/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.)
– Kevin Cruijssen
Dec 13 at 10:20
1
@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
– Jo King
Dec 13 at 10:30
@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}
.
– maxb
Dec 13 at 10:34
@JoKing I'll add a TODO to fix the docs for the slicing operators.
– maxb
Dec 13 at 10:35
1
15 bytes using @KevinCruijssen's solution
– Jo King
Dec 13 at 10:46
|
show 3 more comments
How does theif/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.)
– Kevin Cruijssen
Dec 13 at 10:20
1
@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
– Jo King
Dec 13 at 10:30
@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}
.
– maxb
Dec 13 at 10:34
@JoKing I'll add a TODO to fix the docs for the slicing operators.
– maxb
Dec 13 at 10:35
1
15 bytes using @KevinCruijssen's solution
– Jo King
Dec 13 at 10:46
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.)– Kevin Cruijssen
Dec 13 at 10:20
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.)– Kevin Cruijssen
Dec 13 at 10:20
1
1
@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– Jo King
Dec 13 at 10:30
@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– Jo King
Dec 13 at 10:30
@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}
.– maxb
Dec 13 at 10:34
@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}
.– maxb
Dec 13 at 10:34
@JoKing I'll add a TODO to fix the docs for the slicing operators.
– maxb
Dec 13 at 10:35
@JoKing I'll add a TODO to fix the docs for the slicing operators.
– maxb
Dec 13 at 10:35
1
1
15 bytes using @KevinCruijssen's solution
– Jo King
Dec 13 at 10:46
15 bytes using @KevinCruijssen's solution
– Jo King
Dec 13 at 10:46
|
show 3 more comments
up vote
4
down vote
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
1
ç
auto-casts its first parameter into a string, so you can drop the'
.
– Oliver
Dec 13 at 0:21
1
You don't need theu
method thanks to index wrapping so this can be 14 bytes.
– Shaggy
Dec 13 at 8:13
add a comment |
up vote
4
down vote
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
1
ç
auto-casts its first parameter into a string, so you can drop the'
.
– Oliver
Dec 13 at 0:21
1
You don't need theu
method thanks to index wrapping so this can be 14 bytes.
– Shaggy
Dec 13 at 8:13
add a comment |
up vote
4
down vote
up vote
4
down vote
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
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
edited Dec 13 at 14:07
answered Dec 12 at 18:09
Kamil Drakari
2,961416
2,961416
1
ç
auto-casts its first parameter into a string, so you can drop the'
.
– Oliver
Dec 13 at 0:21
1
You don't need theu
method thanks to index wrapping so this can be 14 bytes.
– Shaggy
Dec 13 at 8:13
add a comment |
1
ç
auto-casts its first parameter into a string, so you can drop the'
.
– Oliver
Dec 13 at 0:21
1
You don't need theu
method thanks to index wrapping so this can be 14 bytes.
– Shaggy
Dec 13 at 8:13
1
1
ç
auto-casts its first parameter into a string, so you can drop the '
.– Oliver
Dec 13 at 0:21
ç
auto-casts its first parameter into a string, so you can drop the '
.– Oliver
Dec 13 at 0:21
1
1
You don't need the
u
method thanks to index wrapping so this can be 14 bytes.– Shaggy
Dec 13 at 8:13
You don't need the
u
method thanks to index wrapping so this can be 14 bytes.– Shaggy
Dec 13 at 8:13
add a comment |
up vote
3
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
3
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
3
down vote
up vote
3
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 Dec 12 at 16:30
Arnauld
71.7k688300
71.7k688300
add a comment |
add a comment |
up vote
3
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
3
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
3
down vote
up vote
3
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 Dec 12 at 17:23
answered Dec 12 at 16:39
Giuseppe
16.5k31052
16.5k31052
add a comment |
add a comment |
up vote
3
down vote
V, 22 bytes
i>
<Àñäkjjé-já-ñÀGjdG
Try it online!
5
This looks like some weird scandinavian language
– Pavel
Dec 12 at 18:02
add a comment |
up vote
3
down vote
V, 22 bytes
i>
<Àñäkjjé-já-ñÀGjdG
Try it online!
5
This looks like some weird scandinavian language
– Pavel
Dec 12 at 18:02
add a comment |
up vote
3
down vote
up vote
3
down vote
V, 22 bytes
i>
<Àñäkjjé-já-ñÀGjdG
Try it online!
V, 22 bytes
i>
<Àñäkjjé-já-ñÀGjdG
Try it online!
answered Dec 12 at 17:50
DJMcMayhem♦
40.8k11145308
40.8k11145308
5
This looks like some weird scandinavian language
– Pavel
Dec 12 at 18:02
add a comment |
5
This looks like some weird scandinavian language
– Pavel
Dec 12 at 18:02
5
5
This looks like some weird scandinavian language
– Pavel
Dec 12 at 18:02
This looks like some weird scandinavian language
– Pavel
Dec 12 at 18:02
add a comment |
up vote
3
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
3
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
3
down vote
up vote
3
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 Dec 12 at 20:59
Neil
78.9k744175
78.9k744175
add a comment |
add a comment |
up vote
3
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
3
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
3
down vote
up vote
3
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 Dec 12 at 21:35
Οurous
6,31811032
6,31811032
add a comment |
add a comment |
up vote
3
down vote
JavaScript, 49 bytes
f=n=>--n?f(n,l='')+(n%2?`
<`+l:`
${l+='-'}>`):'>'
Try it online!
Wow, pretty cool
– Levitator Imbalance
Dec 14 at 10:41
...but it throws on10000
, meanwhile my ES6 solution is still works :D Anyway, your solution is very cool)
– Levitator Imbalance
Dec 14 at 10:53
add a comment |
up vote
3
down vote
JavaScript, 49 bytes
f=n=>--n?f(n,l='')+(n%2?`
<`+l:`
${l+='-'}>`):'>'
Try it online!
Wow, pretty cool
– Levitator Imbalance
Dec 14 at 10:41
...but it throws on10000
, meanwhile my ES6 solution is still works :D Anyway, your solution is very cool)
– Levitator Imbalance
Dec 14 at 10:53
add a comment |
up vote
3
down vote
up vote
3
down vote
JavaScript, 49 bytes
f=n=>--n?f(n,l='')+(n%2?`
<`+l:`
${l+='-'}>`):'>'
Try it online!
JavaScript, 49 bytes
f=n=>--n?f(n,l='')+(n%2?`
<`+l:`
${l+='-'}>`):'>'
Try it online!
edited Dec 13 at 5:49
answered Dec 13 at 3:17
tsh
8,31511546
8,31511546
Wow, pretty cool
– Levitator Imbalance
Dec 14 at 10:41
...but it throws on10000
, meanwhile my ES6 solution is still works :D Anyway, your solution is very cool)
– Levitator Imbalance
Dec 14 at 10:53
add a comment |
Wow, pretty cool
– Levitator Imbalance
Dec 14 at 10:41
...but it throws on10000
, meanwhile my ES6 solution is still works :D Anyway, your solution is very cool)
– Levitator Imbalance
Dec 14 at 10:53
Wow, pretty cool
– Levitator Imbalance
Dec 14 at 10:41
Wow, pretty cool
– Levitator Imbalance
Dec 14 at 10:41
...but it throws on
10000
, meanwhile my ES6 solution is still works :D Anyway, your solution is very cool)– Levitator Imbalance
Dec 14 at 10:53
...but it throws on
10000
, meanwhile my ES6 solution is still works :D Anyway, your solution is very cool)– Levitator Imbalance
Dec 14 at 10:53
add a comment |
up vote
2
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
2
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
2
down vote
up vote
2
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 Dec 12 at 21:59
Felix Palmen
3,331525
3,331525
add a comment |
add a comment |
up vote
2
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
2
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
2
down vote
up vote
2
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 Dec 13 at 0:02
Jo King
20.5k246108
20.5k246108
add a comment |
add a comment |
up vote
2
down vote
K (ngn/k), 31 29 bytes
{"<->"x#2,x{(1=*x)_1,2-|x}}
Try it online!
first we generate lists with 0 instead of "<"
, 1 instead of "-"
, and 2 instead of ">"
:
{
}
function with argument x
x{
...}
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
I would like to ask for an explanation (I haven't started learning K yet, I don't know which version to start with...)
– Galen Ivanov
Dec 13 at 12:14
1
@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?
– ngn
Dec 13 at 12:44
Thank you, I'm already there
– Galen Ivanov
Dec 13 at 12:49
add a comment |
up vote
2
down vote
K (ngn/k), 31 29 bytes
{"<->"x#2,x{(1=*x)_1,2-|x}}
Try it online!
first we generate lists with 0 instead of "<"
, 1 instead of "-"
, and 2 instead of ">"
:
{
}
function with argument x
x{
...}
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
I would like to ask for an explanation (I haven't started learning K yet, I don't know which version to start with...)
– Galen Ivanov
Dec 13 at 12:14
1
@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?
– ngn
Dec 13 at 12:44
Thank you, I'm already there
– Galen Ivanov
Dec 13 at 12:49
add a comment |
up vote
2
down vote
up vote
2
down vote
K (ngn/k), 31 29 bytes
{"<->"x#2,x{(1=*x)_1,2-|x}}
Try it online!
first we generate lists with 0 instead of "<"
, 1 instead of "-"
, and 2 instead of ">"
:
{
}
function with argument x
x{
...}
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
K (ngn/k), 31 29 bytes
{"<->"x#2,x{(1=*x)_1,2-|x}}
Try it online!
first we generate lists with 0 instead of "<"
, 1 instead of "-"
, and 2 instead of ">"
:
{
}
function with argument x
x{
...}
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
edited Dec 13 at 12:29
answered Dec 13 at 11:45
ngn
6,76312459
6,76312459
I would like to ask for an explanation (I haven't started learning K yet, I don't know which version to start with...)
– Galen Ivanov
Dec 13 at 12:14
1
@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?
– ngn
Dec 13 at 12:44
Thank you, I'm already there
– Galen Ivanov
Dec 13 at 12:49
add a comment |
I would like to ask for an explanation (I haven't started learning K yet, I don't know which version to start with...)
– Galen Ivanov
Dec 13 at 12:14
1
@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?
– ngn
Dec 13 at 12:44
Thank you, I'm already there
– Galen Ivanov
Dec 13 at 12:49
I would like to ask for an explanation (I haven't started learning K yet, I don't know which version to start with...)
– Galen Ivanov
Dec 13 at 12:14
I would like to ask for an explanation (I haven't started learning K yet, I don't know which version to start with...)
– Galen Ivanov
Dec 13 at 12:14
1
1
@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?
– ngn
Dec 13 at 12:44
@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?
– ngn
Dec 13 at 12:44
Thank you, I'm already there
– Galen Ivanov
Dec 13 at 12:49
Thank you, I'm already there
– Galen Ivanov
Dec 13 at 12:49
add a comment |
up vote
2
down vote
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
1
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.
– Kevin Cruijssen
Dec 13 at 8:54
1
@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.
– nedla2004
Dec 13 at 23:09
I've posted my answer in that case. :)
– Kevin Cruijssen
Dec 14 at 8:31
add a comment |
up vote
2
down vote
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
1
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.
– Kevin Cruijssen
Dec 13 at 8:54
1
@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.
– nedla2004
Dec 13 at 23:09
I've posted my answer in that case. :)
– Kevin Cruijssen
Dec 14 at 8:31
add a comment |
up vote
2
down vote
up vote
2
down vote
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
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
edited Dec 13 at 23:05
answered Dec 12 at 19:55
nedla2004
4011410
4011410
1
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.
– Kevin Cruijssen
Dec 13 at 8:54
1
@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.
– nedla2004
Dec 13 at 23:09
I've posted my answer in that case. :)
– Kevin Cruijssen
Dec 14 at 8:31
add a comment |
1
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.
– Kevin Cruijssen
Dec 13 at 8:54
1
@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.
– nedla2004
Dec 13 at 23:09
I've posted my answer in that case. :)
– Kevin Cruijssen
Dec 14 at 8:31
1
1
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.– Kevin Cruijssen
Dec 13 at 8:54
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.– Kevin Cruijssen
Dec 13 at 8:54
1
1
@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.
– nedla2004
Dec 13 at 23:09
@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.
– nedla2004
Dec 13 at 23:09
I've posted my answer in that case. :)
– Kevin Cruijssen
Dec 14 at 8:31
I've posted my answer in that case. :)
– Kevin Cruijssen
Dec 14 at 8:31
add a comment |
up vote
2
down vote
ES6, 96 82 79 70 bytes
Try it online! (Thanks to @Oliver)
n=>[...Array(n)].map((_,i)=>(i%2?"<":"")+"-".repeat(i/2)+(i%2?"":">"))
New contributor
1
Welcome to PPCG! By default, taking input as a variable is disallowed; you have to either make it a function (just stick ai=>
in front of your code!) or from a command-line argument or STDIN or something.
– HyperNeutrino
Dec 14 at 14:40
@HyperNeutrino okay, edited answer. However, the most voted answer contains only the body of the function, but ok. Anyway I'm outsider)
– Levitator Imbalance
Dec 14 at 15:09
Can you link it? I don't think any of them are invalid, at least not the top few.
– HyperNeutrino
Dec 14 at 15:16
1
A few more bytes: Try it online
– Oliver
Dec 14 at 16:15
1
A few more bytes if you re-arrange that last ternary operator and remove the center parenthesis: Try it online
– Oliver
Dec 14 at 16:59
|
show 7 more comments
up vote
2
down vote
ES6, 96 82 79 70 bytes
Try it online! (Thanks to @Oliver)
n=>[...Array(n)].map((_,i)=>(i%2?"<":"")+"-".repeat(i/2)+(i%2?"":">"))
New contributor
1
Welcome to PPCG! By default, taking input as a variable is disallowed; you have to either make it a function (just stick ai=>
in front of your code!) or from a command-line argument or STDIN or something.
– HyperNeutrino
Dec 14 at 14:40
@HyperNeutrino okay, edited answer. However, the most voted answer contains only the body of the function, but ok. Anyway I'm outsider)
– Levitator Imbalance
Dec 14 at 15:09
Can you link it? I don't think any of them are invalid, at least not the top few.
– HyperNeutrino
Dec 14 at 15:16
1
A few more bytes: Try it online
– Oliver
Dec 14 at 16:15
1
A few more bytes if you re-arrange that last ternary operator and remove the center parenthesis: Try it online
– Oliver
Dec 14 at 16:59
|
show 7 more comments
up vote
2
down vote
up vote
2
down vote
ES6, 96 82 79 70 bytes
Try it online! (Thanks to @Oliver)
n=>[...Array(n)].map((_,i)=>(i%2?"<":"")+"-".repeat(i/2)+(i%2?"":">"))
New contributor
ES6, 96 82 79 70 bytes
Try it online! (Thanks to @Oliver)
n=>[...Array(n)].map((_,i)=>(i%2?"<":"")+"-".repeat(i/2)+(i%2?"":">"))
New contributor
edited Dec 14 at 17:02
New contributor
answered Dec 14 at 10:35
Levitator Imbalance
1213
1213
New contributor
New contributor
1
Welcome to PPCG! By default, taking input as a variable is disallowed; you have to either make it a function (just stick ai=>
in front of your code!) or from a command-line argument or STDIN or something.
– HyperNeutrino
Dec 14 at 14:40
@HyperNeutrino okay, edited answer. However, the most voted answer contains only the body of the function, but ok. Anyway I'm outsider)
– Levitator Imbalance
Dec 14 at 15:09
Can you link it? I don't think any of them are invalid, at least not the top few.
– HyperNeutrino
Dec 14 at 15:16
1
A few more bytes: Try it online
– Oliver
Dec 14 at 16:15
1
A few more bytes if you re-arrange that last ternary operator and remove the center parenthesis: Try it online
– Oliver
Dec 14 at 16:59
|
show 7 more comments
1
Welcome to PPCG! By default, taking input as a variable is disallowed; you have to either make it a function (just stick ai=>
in front of your code!) or from a command-line argument or STDIN or something.
– HyperNeutrino
Dec 14 at 14:40
@HyperNeutrino okay, edited answer. However, the most voted answer contains only the body of the function, but ok. Anyway I'm outsider)
– Levitator Imbalance
Dec 14 at 15:09
Can you link it? I don't think any of them are invalid, at least not the top few.
– HyperNeutrino
Dec 14 at 15:16
1
A few more bytes: Try it online
– Oliver
Dec 14 at 16:15
1
A few more bytes if you re-arrange that last ternary operator and remove the center parenthesis: Try it online
– Oliver
Dec 14 at 16:59
1
1
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.– HyperNeutrino
Dec 14 at 14:40
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.– HyperNeutrino
Dec 14 at 14:40
@HyperNeutrino okay, edited answer. However, the most voted answer contains only the body of the function, but ok. Anyway I'm outsider)
– Levitator Imbalance
Dec 14 at 15:09
@HyperNeutrino okay, edited answer. However, the most voted answer contains only the body of the function, but ok. Anyway I'm outsider)
– Levitator Imbalance
Dec 14 at 15:09
Can you link it? I don't think any of them are invalid, at least not the top few.
– HyperNeutrino
Dec 14 at 15:16
Can you link it? I don't think any of them are invalid, at least not the top few.
– HyperNeutrino
Dec 14 at 15:16
1
1
A few more bytes: Try it online
– Oliver
Dec 14 at 16:15
A few more bytes: Try it online
– Oliver
Dec 14 at 16:15
1
1
A few more bytes if you re-arrange that last ternary operator and remove the center parenthesis: Try it online
– Oliver
Dec 14 at 16:59
A few more bytes if you re-arrange that last ternary operator and remove the center parenthesis: Try it online
– Oliver
Dec 14 at 16:59
|
show 7 more comments
up vote
2
down vote
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!
1
-1 for removing a space
– NK1406
Dec 15 at 18:28
@NK1406 Thank you! I didn't know this is valid.
– Galen Ivanov
Dec 15 at 19:01
add a comment |
up vote
2
down vote
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!
1
-1 for removing a space
– NK1406
Dec 15 at 18:28
@NK1406 Thank you! I didn't know this is valid.
– Galen Ivanov
Dec 15 at 19:01
add a comment |
up vote
2
down vote
up vote
2
down vote
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!
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!
edited Dec 15 at 19:00
answered Dec 13 at 9:18
Galen Ivanov
6,21711032
6,21711032
1
-1 for removing a space
– NK1406
Dec 15 at 18:28
@NK1406 Thank you! I didn't know this is valid.
– Galen Ivanov
Dec 15 at 19:01
add a comment |
1
-1 for removing a space
– NK1406
Dec 15 at 18:28
@NK1406 Thank you! I didn't know this is valid.
– Galen Ivanov
Dec 15 at 19:01
1
1
-1 for removing a space
– NK1406
Dec 15 at 18:28
-1 for removing a space
– NK1406
Dec 15 at 18:28
@NK1406 Thank you! I didn't know this is valid.
– Galen Ivanov
Dec 15 at 19:01
@NK1406 Thank you! I didn't know this is valid.
– Galen Ivanov
Dec 15 at 19:01
add a comment |
up vote
2
down vote
C (gcc), 127 95 + 26 = 121 bytes
i,j;f(x){for(i=0;i<x;putchar(10),i+=2){for(j=0;E;printf(">n%c",x-i-1?60:9);for(j=0;x-i-1&&E;}}
Try it online!
Compile with -DE=j<i/2;++j)putchar(45)
-6 bytes from Logern
Yay mismatched parentheses!
Ungolfed:
void f(int x) {
for (int i = 0; i < x; i += 2) {
for (int j = 0; j < i/2; ++j) {
printf("-");
}
printf(">n");
if (x - i - 1) { // Test for last loop: only print <-- if x is even
printf("<");
for (int j = 0; j < i/2; ++j) {
printf("-");
}
}
else {
printf("t"); // This is the 9 in the x-i-1?60:9
}
printf("n");
}
}
Try it online!
1
121 bytes with a -D compiler flag instead of #define - Try it online!
– Logern
Dec 14 at 17:31
Another -3 bytes by taking out the i=0 like this
– NK1406
Dec 15 at 18:19
@NK1406 Functions have to be reusable, that edit would break this rule. Try it online!
– pizzapants184
2 days ago
Suggestx+~i
instead ofx-i-1
– ceilingcat
2 days ago
@pizzapants184 Sorry, didn't see that!
– NK1406
2 days ago
add a comment |
up vote
2
down vote
C (gcc), 127 95 + 26 = 121 bytes
i,j;f(x){for(i=0;i<x;putchar(10),i+=2){for(j=0;E;printf(">n%c",x-i-1?60:9);for(j=0;x-i-1&&E;}}
Try it online!
Compile with -DE=j<i/2;++j)putchar(45)
-6 bytes from Logern
Yay mismatched parentheses!
Ungolfed:
void f(int x) {
for (int i = 0; i < x; i += 2) {
for (int j = 0; j < i/2; ++j) {
printf("-");
}
printf(">n");
if (x - i - 1) { // Test for last loop: only print <-- if x is even
printf("<");
for (int j = 0; j < i/2; ++j) {
printf("-");
}
}
else {
printf("t"); // This is the 9 in the x-i-1?60:9
}
printf("n");
}
}
Try it online!
1
121 bytes with a -D compiler flag instead of #define - Try it online!
– Logern
Dec 14 at 17:31
Another -3 bytes by taking out the i=0 like this
– NK1406
Dec 15 at 18:19
@NK1406 Functions have to be reusable, that edit would break this rule. Try it online!
– pizzapants184
2 days ago
Suggestx+~i
instead ofx-i-1
– ceilingcat
2 days ago
@pizzapants184 Sorry, didn't see that!
– NK1406
2 days ago
add a comment |
up vote
2
down vote
up vote
2
down vote
C (gcc), 127 95 + 26 = 121 bytes
i,j;f(x){for(i=0;i<x;putchar(10),i+=2){for(j=0;E;printf(">n%c",x-i-1?60:9);for(j=0;x-i-1&&E;}}
Try it online!
Compile with -DE=j<i/2;++j)putchar(45)
-6 bytes from Logern
Yay mismatched parentheses!
Ungolfed:
void f(int x) {
for (int i = 0; i < x; i += 2) {
for (int j = 0; j < i/2; ++j) {
printf("-");
}
printf(">n");
if (x - i - 1) { // Test for last loop: only print <-- if x is even
printf("<");
for (int j = 0; j < i/2; ++j) {
printf("-");
}
}
else {
printf("t"); // This is the 9 in the x-i-1?60:9
}
printf("n");
}
}
Try it online!
C (gcc), 127 95 + 26 = 121 bytes
i,j;f(x){for(i=0;i<x;putchar(10),i+=2){for(j=0;E;printf(">n%c",x-i-1?60:9);for(j=0;x-i-1&&E;}}
Try it online!
Compile with -DE=j<i/2;++j)putchar(45)
-6 bytes from Logern
Yay mismatched parentheses!
Ungolfed:
void f(int x) {
for (int i = 0; i < x; i += 2) {
for (int j = 0; j < i/2; ++j) {
printf("-");
}
printf(">n");
if (x - i - 1) { // Test for last loop: only print <-- if x is even
printf("<");
for (int j = 0; j < i/2; ++j) {
printf("-");
}
}
else {
printf("t"); // This is the 9 in the x-i-1?60:9
}
printf("n");
}
}
Try it online!
edited 2 days ago
answered Dec 14 at 6:23
pizzapants184
2,644716
2,644716
1
121 bytes with a -D compiler flag instead of #define - Try it online!
– Logern
Dec 14 at 17:31
Another -3 bytes by taking out the i=0 like this
– NK1406
Dec 15 at 18:19
@NK1406 Functions have to be reusable, that edit would break this rule. Try it online!
– pizzapants184
2 days ago
Suggestx+~i
instead ofx-i-1
– ceilingcat
2 days ago
@pizzapants184 Sorry, didn't see that!
– NK1406
2 days ago
add a comment |
1
121 bytes with a -D compiler flag instead of #define - Try it online!
– Logern
Dec 14 at 17:31
Another -3 bytes by taking out the i=0 like this
– NK1406
Dec 15 at 18:19
@NK1406 Functions have to be reusable, that edit would break this rule. Try it online!
– pizzapants184
2 days ago
Suggestx+~i
instead ofx-i-1
– ceilingcat
2 days ago
@pizzapants184 Sorry, didn't see that!
– NK1406
2 days ago
1
1
121 bytes with a -D compiler flag instead of #define - Try it online!
– Logern
Dec 14 at 17:31
121 bytes with a -D compiler flag instead of #define - Try it online!
– Logern
Dec 14 at 17:31
Another -3 bytes by taking out the i=0 like this
– NK1406
Dec 15 at 18:19
Another -3 bytes by taking out the i=0 like this
– NK1406
Dec 15 at 18:19
@NK1406 Functions have to be reusable, that edit would break this rule. Try it online!
– pizzapants184
2 days ago
@NK1406 Functions have to be reusable, that edit would break this rule. Try it online!
– pizzapants184
2 days ago
Suggest
x+~i
instead of x-i-1
– ceilingcat
2 days ago
Suggest
x+~i
instead of x-i-1
– ceilingcat
2 days ago
@pizzapants184 Sorry, didn't see that!
– NK1406
2 days ago
@pizzapants184 Sorry, didn't see that!
– NK1406
2 days ago
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 Dec 12 at 17:47
mazzy
2,0151314
2,0151314
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 Dec 12 at 22:25
Xcali
5,148520
5,148520
add a comment |
add a comment |
1 2
next
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
2
Related.
– AdmBorkBork
Dec 12 at 16:23
Can we have spaces before/after each line?
– Olivier Grégoire
Dec 12 at 16:54
@OlivierGrégoire Yes, trailing whitespace is ok.
– Pavel
Dec 12 at 16:55
And heading whitespace?
– Olivier Grégoire
Dec 12 at 16:58
@OlivierGrégoire Yeah, that's fine.
– Pavel
Dec 12 at 17:00