| Bytes | Lang | Time | Link |
|---|---|---|---|
| 011 | Vyxal 3 | 250825T123203Z | Themooni |
| 060 | AWK | 250822T184101Z | xrs |
| 052 | YASEPL | 240213T193241Z | madeforl |
| 020 | Perl 5 + p | 240215T131018Z | Dom Hast |
| 133 | Go | 240214T143253Z | bigyihsu |
| 059 | JavaScript Node.js | 240214T121626Z | noodle p |
| 008 | Vyxal | 240213T234537Z | emanresu |
| 019 | J | 240213T233416Z | Jonah |
| 087 | TypeScript's type system | 240213T203129Z | noodle p |
| nan | Vyxal j | 240213T132843Z | pacman25 |
| 012 | MATL | 190610T111229Z | Suever |
| 046 | Zsh | 210422T200947Z | pxeger |
| 072 | Forth gforth | 201110T090825Z | Razetime |
| 023 | Husk | 201005T074023Z | Razetime |
| 085 | Rockstar | 200911T143033Z | Shaggy |
| 069 | MAWP | 200816T063002Z | Razetime |
| 086 | Python 3 | 200325T183008Z | Dion |
| 069 | Erlang escript | 200325T074249Z | user9206 |
| 059 | Perl 5 | 191014T155955Z | rpGYNay0 |
| 055 | Python 3 | 191014T035349Z | Matthew |
| 074 | \/\/> | 190705T051141Z | torcado |
| nan | PHP | 190617T184051Z | 640KB |
| 091 | Pepe | 190616T141123Z | u-ndefin |
| 133 | Rockstar | 190615T170504Z | gaborsch |
| 091 | Swift 5/Xcode 10.2.1 | 190610T111154Z | Roman Po |
| 056 | Ruby | 190609T225445Z | Sixtyfiv |
| 125 | brainfuck | 190613T194859Z | Helena |
| 080 | Python 3.8 prerelease | 190613T150544Z | squid |
| 083 | Python 3 | 190612T145940Z | Miriam |
| 677 | MarioLANG | 190610T103036Z | Charlie |
| 018 | Pyth | 190612T113516Z | Sok |
| 1179 | Batch File | 190611T231319Z | BDM |
| 056 | C gcc | 190609T102538Z | att |
| 019 | Pyth | 190612T021332Z | DoggyDog |
| 023 | Pyth | 190611T202226Z | trillian |
| 015 | Japt R | 190611T154116Z | Shaggy |
| 080 | Java 8 | 190611T144925Z | Kevin Cr |
| 049 | Haskell | 190609T181844Z | Joseph S |
| 052 | C64Mini/C64 BASIC and other CBM BASIC variants | 190610T112253Z | Shaun Be |
| 115 | Twig | 190610T064636Z | Ismael M |
| 042 | JavaScript Node.js | 190610T013428Z | Shieru A |
| 100 | SimpleTemplate | 190610T061647Z | Ismael M |
| 041 | PowerShell | 190610T051846Z | mazzy |
| 050 | PowerShell | 190610T021913Z | Veskah |
| 010 | Stax | 190609T232117Z | recursiv |
| 075 | Python 2 | 190609T192759Z | ruohola |
| 065 | C gcc | 190609T061317Z | gastropn |
| 080 | TSQL code | 190609T123854Z | t-clause |
| 032 | Retina 0.8.2 | 190609T100824Z | Neil |
| 006 | 05AB1E | 190609T095506Z | Emigna |
| 080 | APLNARS | 190609T092635Z | user5898 |
| 005 | Charcoal | 190609T085851Z | Neil |
| 002 | Canvas | 190609T073343Z | dzaima |
| 054 | Python 2 | 190609T062136Z | xnor |
| 063 | Python 2 | 190609T060924Z | Chas Bro |
| 036 | Perl 5 p | 190609T060108Z | Xcali |
| 066 | C# Visual C# Interactive Compiler | 190609T045042Z | Gymhgy |
Vyxal 3, 11 bytes
ƛᏜ\/f«⍟U⇄J”
ƛᏜ\/f«⍟U⇄J”
ƛ ⍟ # map over implicit range implicit input, then flatten
« # pad left with n spaces...
Ꮬ\/f # each in the array ['\','/']
U # uninterleave, extracting the tail
⇄ # reverse that
J” # join it at the end, and join by newlines
💎
Created with the help of Luminespire.
<script type="vyxal3">
ƛᏜ\/f«⍟U⇄J”
</script>
<script>
args=[["2"],["5"]]
</script>
<script src="https://themoonisacheese.github.io/snippeterpreter/snippet.js" type="module"/>
YASEPL, 58 52 bytes
=i=a'`1=b;" ",i~>"\"!+}7,a`2-=b;" ",i~>divide!}7,0,2
explanation:
=i=a'`1=b;" ",i~>"\"!+}7,a`2-=b;" ",i~>divide!}7,0,2 packed
=i I = increment variable
=a' get user input (arrow size)
`1 ! }7,a while I != A ...
=b;" ",i~>"\" write I amount of spaces and a backslash
+ increment I and loop
`2 !}7,0,2 while I != 0...
- subtract 1 from I
=b;" ",i~>divide write I amount of spaces and a slash
and just for fun...
ibe, 118 bytes
adadadadadadaddsRafWmreafYmpeafUmtiakqskTagTmwakwafTmwslWssTmQmwaaYafQmwssQmRmqakeskTakrafTmwslWssTmQmraaUagQmwsaQmqme
(this is an esolang i made a while ago that i dont plan on releasing)
Perl 5 + -p, 20 bytes
Uses non-printable characters (backspace 0x08 and form feed 0x0c) to position the characters in the terminal.
$_='\.'x$_."./.."x$_
Explanation
Stores in $_ a repetition of the literal string \<FF> $_ (implicit input) times, concatenated with <BS>/<FF><BS> repeated $_ times.
$_ is then output implicitly by -p.
Go, 133 bytes
import."strings"
func f(n int)(o string){for i:=0;i<n;i++{o+=Repeat(` `,i)+"\\\n"}
for i:=n;i>0;i--{o+=Repeat(` `,i-1)+"/\n"}
return}
Go 1.22+, 131 bytes
import."strings"
func f(n int)(o string){for i:=range n{o+=Repeat(` `,i)+"\\\n"}
for i:=range n{o+=Repeat(` `,n-i-1)+"/\n"}
return}
JavaScript (Node.js), 59 bytes
n=>eval("for(o='';s=''.padEnd(n--);)o=s+`\\\\\n${o+s}/\n`")
I had a different idea, it didn't turn out as golfy as the obvious method but I still felt like posting it.
The program constructs the string with a for loop, counting down from n, and continuously sets a string o to: n spaces, backtick, newline, o, n spaces, forward slash, newline.
Vyxal, 8 bytes
ɾ\\↳↲øṀ§
↳ # Right-pad
\\ # \
ɾ # To length each of range(1, n+1)
↲ # Left-pad each to length n
øṀ # Mirror, flipping slashes
§ # Vertical join, transposing and joining by newlines
TypeScript's type system, 87 bytes
//@ts-nocheck
type F<N,S="">=N extends[{},...infer N]?`
${S}\\${F<N,`${S} `>}
${S}/`:""
Try it at the TypeScript playground
Takes input as a unary number represented by a tuple type N. If I instead took the unary number as a string type of spaces, this becomes 71 bytes:
type F<S,O=''>=S extends` ${infer S}`?F<S,`${S}\\
${O&string}${S}/
`>:O
I like the shorter version better because it's tail-recursive and just overall really elegant, but I think the I/O format is a little cheaty.
Vyxal j, 95 bitsv2, 11.875 bytes
ƛI\\JøṀ;½fyRṘJ
Bitstring:
00001000000011101111110001100110011110111010010010110001001000111000011010000100001110000011111
Beats all non-canvas users
MATL, 14 13 12 bytes
Xy92*t45-Pvc
1 Byte saved thanks to @LuisMendo
Explanation
% Implicitly grab the input as an integer
Xy % Create an identity matrix this size
92* % Multiply by 92 (ASCII for '\')
t % Duplicate the matrix
45- % Subtract 45 from every element yielding 47 (ASCII for '/') on the diagonal
% and -45 everywhere else
P % Vertically flip this matrix
v % Vertically concatenate the two matrices
c % Convert to characters (negative numbers are replaced with a space)
% Implicitly display the result
Try it out at MATL Online
Zsh, 46 bytes
/ \\()for a;<<<${(l:a:)0};\\ {1..$1};/ {$1..1}
It really ought to be possible to get shorter than this...
Forth (gforth), 72 bytes
: f dup 0 ?do i spaces 92 emit cr loop 1- for i spaces 47 emit cr next ;
there's probably a better way to do this.
Rockstar, 85 bytes
listen to N
X's0
while N-X
say " "*X+"\"
let X be+1
while X
let X be-1
say " "*X+"/"
Try it here (Code will need to be pasted in)
MAWP, 69 bytes
%@!0//[!1A]%[1A[1A84W;]%99W25WM1M;25W;]%[!1A]~[1A[1A84W;]%67W5M;25W;]
I am not going to golf this further bcause funny number. Sorry, guys.
Python 3, 91 86 bytes
n=range(int(input()))
for i in n:print(' '*i+'\\')
for i in n:print(' '*(n[-1]-i)+'/')
Edit 1: saved 5 bytes by making n a range instead of integer
Erlang (escript), 69 bytes
Port of xnor's Python answer.
r(0,_)->"";r(I,X)->X++"\\\n"++r(I-1,X++" ")++X++"/\n".
r(I)->r(I,"").
Perl 5, 59 bytes
$_--;say$"x$_."\\"for(0..$_);say$"x$_."/"for(reverse 0..$_)
Example execution:
perl -nE '$_--;say$"x$_."\\"for(0..$_);say$"x$_."/"for(reverse 0..$_)'
Waits for an integer to be provided on STDIN when executed. Once provided, it will display the arrow.
\/\/>, 74 bytes
jp100o
-84*}!o:?!x1
@+:q:p=?x:o~$:0(pa"\/"q?$~}}:
x2-:p$1-y$:0(?
.{suh?!;2
Explanation: (lines rotated based on start point)
jp100o //setup
:?!x1-84*}! //add leading spaces, loop and decrement until 0
~$:0(pa"\/"q?$~}}:@+:q:p=?x:o //add correct slash, go back to loop or switch sides
$:0(?x2-:p$1-y //flip direction state or continue to print
{suh?!;2. //remove extra data and print stack
PHP, 79 63 61 bytes
function f($x,$s=''){if($x)echo"$s\\
",f($x-1,"$s "),"$s/
";}
Recursive in PHP.
-12 bytes by @manatwork
Pepe, 91 bytes
rErEeEeEEEeeREeEREErereeereeERrEeeEeeeeeRrEeeeReereRerEEEererEeeEeEEEErEEEEREErereeereeERee
Rockstar, 133 bytes
Try it online here!
F takes N,S
If N is 0
Give back N
Say S+"\"
Let T be S+" "
Let M be N-1
F taking M,T
Say S+"/"
Listen to X
F taking X,""
Since Rockstar is not famous for string operations, it takes relatively lots of code to do it (recursively was even longer).
The size of the arrow is taken as input.
Swift 5/Xcode 10.2.1, 91 bytes
(0..<n*2).map{String(repeating:" ",count:$0<n ?$0:n*2-$0-1)+($0<n ?"\\":"/")+"\n"}.joined()
Ruby, 111 99 77 73 68 64 57 56 bytes
-12 bytes thanks to Benjamin Urquhart, -43 thanks to manatwork and -2 bytes thanks to Value Ink.
->i{s=[];puts (0...i).map{|j|s=(p=' '*j)+?/,*s;p+?\\},s}
Explanation:
f=->i{ # instead of a function, use a lambda
s=[] # needs a helper variable *now*, for scope
puts( # puts takes arbitrary num of args; \n after each
(0...i).map{|j| # not from 0 to i but from 0 to i-1 (*three* dots)
s=(
p=' '*j # p will remain in scope inside of .map,
)
+?/ # character literal instead of string
,*s # essentially appending to the array
p+?\\ # p is what's returned by .map, not s!
}, # up until here, 1st arg to display
s # NOW, as the *2nd* arg, s is displayed
)
}
Alternative (but longer) Solutions
A friend read this answer and then tried to come up with a couple more approaches. Putting them here, too, so that they're not lost to the vast interwebs.
inject and unshift, 72 bytes
->n{puts (0...n).inject([]){|s,i|i=' '*(n-1-i);s.unshift i+?\\;s<<i+?/}}
downto, inject and unshift, 80 bytes
->n{puts n.downto(1).map{|i|' '*(i-1)}.inject([]){|s,i|s<<i+?/;s.unshift i+?\\}}
intriguing, two non-nested loops, 127 bytes
->n{
r=->s,c{s[0..-(c+1)],s[-c..-1]=s[c..-1],s[0..c-1];s};
n.times{|i|puts r[' '*n+?\\,n-i]}
n.times{|i|puts r[' '*n+?/,i+1]}
}
brainfuck, 125 bytes
++++++++++[->+>+++++++++>+++<<<]>>++>++>,[->[->+<<<.>>]<<<.<.>>>>>[-<+>]<+<]<<[--<<+>>]<<+>>>>>[-[-<+<.>>]<<<<<.>.>>>[->+<]>]
++++++++++[->+>+++++++++>+++<<<]>>++>++> ; Initialize with " \"
, ; Get input
[-> ; loop and decrement n
[->+<<<.>>] ; output number of spaces, copy n
<<<. ; output \
<. ; output newline
>>>>
>[-<+>]<+ ; copy copy of n back to original place
<]
<<[--<<+>>]<<+>> ; change "\" to "/"
>>>
[ ; second loop for bottom half
- ; decrement n
[-<+<.>>] ; output n spaces
<<<<<.>. ; output \ and newline
>>>[->+<]> ; copy n back
]
Python 3.8 (pre-release), 80 bytes
lambda n:'\n'.join([' '*i+'\\'for i in(r:=range(n))]+[' '*(n+~i)+'/'for i in r])
Same approach as the one I suggested to @Artemis Fowl, but takes advantage of the walrus operator.
Python 3, 90 83 bytes
lambda n:'\n'.join([' '*i+'\\'for i in range(n)]+[' '*(n+~i)+'/'for i in range(n)])
-7 bytes thanks to @squid
MarioLANG, 719 677 bytes
+
+
+
+
+
+ ((((+)+++++)))<
+>======================"
+)++++++)+++++++++++((-[!)
========================#=-
) ![- <+;)+++)---)++++)<
)=#======"=================
) >)+)+((!
+ "======#
<))))).(((((((<
========">============"
>)+)+((-[!+)) -[!((((((((.)).))))+(-[!)
"========#=============#====================#<
!) <
#==========================================="
>(((((.)))>
"========<"========
![-)).))).(((((((![- ))+![-((+)+)<((![<
#================#=========#========"==#="===
> ! >-!
"===================================# "=#
This was harder than expected...
Batch File, 117 + 9 bytes
Executed using cmd/v/q/c.
for /l %%i in (1,1,%1)do (for /l %%j in (2,1,%%i)do set %%i= !%%i!)&echo !%%i!\
for /l %%i in (%1,-1,1)do echo !%%i!/
C (gcc), 56 bytes
f(n,i){for(i=-n;n;printf("%*c\n",i?++i+n:n--,i?92:47));}
f(n,i){for(i=-n;i;printf("%*c\n", ++i+n , 92 )); //first print descending '\'s
for( ;n;printf("%*c\n", n--, 47));} // then print returning '/'s
Pyth, 19 bytes
VQ+*dN\\)V_Q+*dhN\/
TIL multiplying a string by a negative value multiplies it by its absolute value.
Pyth, 23 bytes
V2VQ
+*?N--QH1H\ ?N\/\\
Note that the program must not have a terminating newline! If saving it on linux, you can remove the last byte in a file using head -c -1 <file>.
I think this is the first time I have used for loops in pyth? Anyways, this is a rather direct port of the example source code in the question (though the 2 loops are combined, and the innermost loop is converted into string multiplication, and the remaining 2 prints are joined into one).
Java 8, 80 bytes
n->{for(int i=0;i<2*n;)System.out.printf("%"+(i++<n?i:n-~n-i)+"c\n",i>n?47:92);}
Explanation:
n->{ // Method with integer parameter and no return-type
for(int i=0;i<2*n;) // Loop `i` in the range [0, 2 * input `n`):
System.out.printf( // Print with format:
"%"+(i++<n? // If `i` is smaller than input `n`:
// (and increase `i` by 1 right after this check with `i++`)
i // Use `i` leading spaces
: // Else:
n-~n-i) // Use `2 * n - i + 1` leading spaces
+"c\n",i>n? // If `i` is larger than input `n`:
47 // Append a trailing '/' and newline
: // Else:
92);} // Append a trailing '\' and newline
Haskell, 52 49 bytes
-3 bytes thanks to Sriotchilism O'Zaic.
unlines.g
g 0=[]
g n="\\":map(' ':)(g$n-1)++["/"]
C64Mini/C64 BASIC (and other CBM BASIC variants), 52 tokenized BASIC bytes used
0INPUTN:N=N-1:FORI=0TON:PRINTTAB(I)"\":NEXT:FORI=NTO0STEP-1:PRINTTAB(I)"/":NEXT
Here is the non-obfuscated version for exaplantion:
0 INPUT N
1 LET N=N-1
2 FOR I=0 TO N
3 PRINT TAB(I);"\"
4 NEXT I
5 FOR I=N TO 0 STEP -1
6 PRINT TAB(I);"/"
7 NEXT I
What ever number is entered into N in line zero is reduced by one as the TAB command is zero-indexed; The FOR/NEXT loops in lines two through to four and five through to seven then output the upper and lower part if the meme arrow respectively (represented by a shifted M and shifted N in graphics mode source)
Twig, 115 bytes
Builds the string backwards, "returning" it in the end.
Uses a macro to generate all the results.
{%macro a(N,s="")%}{%for i in N..1%}{%set s=('%'~i~'s
'~s~'%'~i~'s
')|format('\\','/')%}{%endfor%}{{s}}{%endmacro%}
This macro has to be in a file, and imported like this:
{% import 'macro.twig' as a %}
{{ a.a(<value>) }}
You can try it on https://twigfiddle.com/5hzlpz (click on "Show raw result").
JavaScript (Node.js), 42 bytes (If trailing new line is allowed)
n=>(F=s=>n--?s+`\\
`+F(s+" ")+s+`/
`:"")``
JavaScript (Node.js), 48 46 bytes
n=>(F=s=>s+`\\
${--n?F(s+" ")+`
`:""}${s}/`)``
SimpleTemplate, 100 bytes
This was quite a fun challenge, but some bugs in the language made it hard to optimize.
{@set_ argv.0}{@while_}{@callstr_repeat intoS" ",_}{@setO S,"\\\n",O,S,"/\n"}{@incby-1_}{@/}{@echoO}
Basically, cycles throught the values backwards, working the string from the middle out.
How the answer should be
Due to the bugs, the code wasn't being interpreted properly.
This is how the code would be, if the compiler didn't had any bug (86 bytes):
{@forfrom argv.0to0step-1}{@callrepeat intoS" ",_}{@setO S,"\\
",O,S,"/
"}{@/}{@echoO}
Oh, well, at least the solution works :x
PowerShell, 50 bytes
param($n)0..--$n|%{' '*$_+'\'}
$n..0|%{' '*$_+'/'}
Will look into making it so it only goes through the range once. Not bad for the no brain method though.
Python 2, 85 84 81 80 75 bytes
def a(n):l="for i in range(n):print' '*";exec l+"i+'\\\\'\n"+l+"(n+~i)+'/'"
C (gcc), 67 65 bytes
-2 bytes thanks to ceilingcat
f(n,i){for(i=~n;i++<n;)i&&printf("%*c\n",n-abs(i)+1,"/\\"[i<0]);}
T-SQL code, 80 bytes
DECLARE @ INT=3
,@z INT=0
x:PRINT
space(@-abs(@-@z-.5))+char(92-@z/@*45)SET
@z+=1IF @z<@*2GOTO x
T-SQL query, 96 bytes
In order to make this work online i had to make some minor alterations. Spaces in the beginning of a row doesn't display in the online snippet. So I am using ascii 160 instead. When running in management studio, it is possible to change the settings to show result as text, which would result in the correct spaces in this posted script.
DECLARE @ INT=3
SELECT space(@-abs(@-number-.5))+char(92-number/@*45)FROM
spt_values WHERE number<@*2and'p'=type
Retina 0.8.2, 32 bytes
.+
$* ¶$&$*
\G.
¶$`\
r`.\G
$'/¶
Try it online! Explanation:
.+
$* ¶$&$*
Generate two lines of n spaces.
\G.
¶$`\
Turn the top line into a \ diagonal.
r`.\G
$'/¶
Turn the bottom line into a / diagonal.
05AB1E, 6 bytes
'\3.Λ∊
Explanation
.Λ # draw
'\ # the string "\"
# of length input
3 # in the south-eastern direction
∊ # then vertically mirror it
APL(NARS), 40 chars, 80 bytes
{f←{⍺,⍨⍵⍴' '}⋄⊃('\'f¨k),('/'f¨⌽k←¯1+⍳⍵)}
test:
h←{f←{⍺,⍨⍵⍴' '}⋄⊃('\'f¨k),('/'f¨⌽k←¯1+⍳⍵)}
h 2
\
\
/
/
h 5
\
\
\
\
\
/
/
/
/
/
Charcoal, 5 bytes
↘N‖M↓
Try it online! Link is to verbose version of code. Explanation:
↘N
Input a number and print a diagonal line of \s of that length.
‖M↓
Reflect the line vertically.
Python 2, 54 bytes
f=lambda n,p='':n*'?'and p+'\\\n'+f(n-1,p+' ')+p+'/\n'
Outputs with a trailing newline.
C# (Visual C# Interactive Compiler), 66 bytes
n=>new int[n*2].Select((a,b)=>"".PadLeft(b<n?b:n*2+~b)+"\\/"[b/n])
Saved a byte thanks to @someone.
