g | x | w | all
Bytes Lang Time Link
004Regenerate l210627T014748ZDLosc
030AWK250909T174010Zxrs
048Nibbles230515T231218ZDLosc
088Batch220423T234418ZYouserna
113brainfuck220422T201638Zmechabub
008K ngn/k220422T204212Zcoltim
020Risky210730T122259ZAdam
024Perl 5 + n M5.10.0220130T194358ZDom Hast
011BQN211205T055906Zzoomlogo
056Kotlin211219T104827Zrandom p
007Vyxal M211221T203649ZAlan Bag
042Lua211219T054200ZVisckmar
057JavaScript Node.js211217T183448ZAlan Bag
014Dyalog APL210927T183912ZSohang C
039Mathematica210930T030924Zntrupin
01051AC8210622T085348Zzoomlogo
00405AB1E210604T144959Zovs
022Raku210624T215235ZSean
046convey210607T123544ZZeroCode
183Lolwho.Cares210606T170307ZRobot
060C clang210605T020656ZStack Ex
034AWK210605T063656Zcnamejj
031Ruby210605T143201Zgsus
021Julia 1.0210604T152357ZMarcMush
037C clang210604T161129ZArnauld
012BQN210605T071645Zfrasiyav
003Stax210605T043330ZRazetime
041Ruby210605T025503ZLuis Est
080Zephyr210605T020417Zwasif
034Perl 5210605T010840ZChris
040Factor210604T234628Zchunes
031MATLAB/Octave210604T174325Zelementi
039Bash210604T214728ZDigital
057PHP210604T194640ZSlamJamm
039R210604T151747ZdigEmAll
035R210604T185031ZDominic
010CJam210604T165149ZLuis Men
056Java210604T164037ZUnmitiga
025PowerShell210604T163646Zwasif
030Red210604T162039Z9214
042Python 3210604T150250Zwasif
005Japt R210604T151307ZShaggy
004Vyxal jṀ210604T151842Zhyperneu
001Canvas210604T150859Zovs
006Vyxal j210604T145437Za stone
013Retina 0.8.2210604T150615ZNeil
037Python 2210604T150530Zovs
033JavaScript ES6210604T145125ZArnauld
009APL Dyalog Unicode210604T144704ZAdá
010J210604T144558Zxash
007Jelly210604T143137Zcaird co
007Jelly210604T143139Zhyperneu
002Charcoal210604T144050Zwasif
046Python 3.8 prerelease210604T144044Zzoomlogo

Regenerate -l, 4 bytes

 *\\

Takes input as the argument to the -l flag; for example,

python3 regenerate.py -r ' *\\' -l 4
\
 \
  \
   \

Attempt This Online!

Explanation

The regex *\\ matches 0 or more spaces, followed by a backslash. Regenerate finds all strings that match that regex, starting from the shortest: \, \, \, and so forth. By default, each match is printed on its own line, and the -l N option limits the output to the first N matches.

AWK, 30 bytes

{for(;$1--;)print(s=s" ")"\\"}

Attempt This Online!

{for(;$1--;)  # countdown from input
print         # out
(s=s" ")      # append space to string
"\\"}         # slash

Nibbles, 5 4 bytes (8 nibbles)

-2 nibbles thanks to a hint from Darren Smith

$&" "$"\\"

Attempt This Online!

Explanation

$&" "$"\\"
$           Input number
            (Implicit) Map over range from 1 to that number:
 &            Left-justify
      "\\"    string containing a backslash
     $        to a width given by the function argument
  " "         by padding with spaces
            Output each element of that list on a separate line (implicit)

Batch, 88 bytes

@setlocal enabledelayedexpansion&set s=\&for /l %%i in (1,1,%1)do @(echo !s!
set s= !s!)

Takes input from the command line.

brainfuck, 113 bytes

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

Try it online.

First time poster. This was a fun exercise! Please provide criticism, I pretty much went in cold when writing this.

, how long the line should be via char code
>

initialize cell 1 with "\"
>+++++++[<+++++++++++++>-]<+
> 

initialize cell 2 with "\n"
++++++++++
>

initialize cell 3 with " "; go back to beginning
>++++[<+++++>-]<
<<<

start loop at cell 0
[
    >>>> go to cell 4
    [
        ->+>+<< copy the pad value to cells 5 and 6
    ]
    
    > now we move cell 5 to cell 4
    [
        -<+> cell 4 keeps track how much padding we'll need for our next iteration
    ]
    >

    cell 6 keeps track of how many spaces we need to print currently
    [
        <<<  go to space char
        .    print it
        >>>- decrease counter
    ]

    <<<<< move to line char
    .>.   print line and newline
    >>+   move to cell 4 and increase our padding by 1
    <<<<- back to cell 0; subtract line counter
]

K (ngn/k), 8 bytes

" \\"@=:

Try it online!

Risky, 20 bytes

0?+0+_0+0_?+*{*_?+0__?+0+_0+0+_:-+!_/+/

Try it online!

I'm not happy with the byte count.

Perl 5 + -n -M5.10.0, 24 bytes

say$"x$_,v92 for 0..--$_

Try it online!

BQN, 14 11 bytesSBCS

" \\"⊏˜↕=⌜↕

Run online!

¯3 thanks to @ovs

Kotlin, 56 Bytes

Try it online!

fun d(a:Int){var t="";repeat(a){println(t+'\\');t+=" "}}

ungolfed version
I think this code is obvious enough

fun d(a:Int)
{
    var t = ""
    repeat(a)
    {
        println(t + '\\')
        t += " "
    }
}

Vyxal M, 7 bytes

(nI\\+,

Try it Online!

Explanation:

(  # range from 0 to implict input
  n  # loop variable
   I  # push that many spaces
    \\  # backslash literal
      +  # concatenate the spaces with the backslash
       ,  # print

Lua, 42 bytes

for i=1,...do print((" "):rep(i).."\\")end

Try it online!

JavaScript (Node.js), 57 bytes

f=n=>{for(i=0;++i<n+1;){console.log(" ".repeat(i)+"\\")}}

Try it online!

Dyalog APL, 16 14 bytes

Solution - Takes in number of lines as input from user, and returns a string of diagonal line.

' \'[1+∘.=⍨⍳⎕]

Explanation

⎕            ⍝ ⎕ takes input from the user (number of lines)
             ⍝ In the below explanation, I have assumed ⎕ = 9 as input
⍳⎕            ⍝ 1 to 9 : [1,2,3,4,5,6,7,8,9]
∘.=          ⍝ Outer Product with Equality
⍨            ⍝ Apply a function with same argument on both sides
∘.=⍨⍳⎕       ⍝ ∘.=⍨ function applied to array ⍳⎕ = [1,2..9]
             ⍝ This is same as (⍳9) ∘.= (⍳9), which produces Identity Matrix of size 9
1+∘.=⍨⍳⎕     ⍝ Add 1 to each element of previous matrix (since APL uses 1-based index)
' \'[1+∘.=⍨⍳⎕] ⍝ From the string ' \', select characters specified by indices in 1+∘.=⍨⍳⎕

Mathematica, 39 bytes

We save some bytes by using an infix Array over Range, Table over StringRepeat, and Echo over Print.

We also cut it down to 33 bytes in TIO, because user input for Mathematica wasn't working :)

Echo[Table[" ",#]<>"\\"]&~Array~Input[]

Try it online!

51AC8, 10 bytes

R[\ ×\\+t]

Try it Online!

-2 bytes due to an update.

-7 bytes due to an update introducing for_each loops and range.

-1 byte online interpreter and implicit input.

Explanation

       # Implicit Input (STDIN) and push to stack
R      # Range from 0 to input (exclusive)
[      # Start for each
  \    # Push ' ' to the stack
  ×    # Multiply the top 2 elements on the stack
  \\   # Push '\'
  +    # Add top 2 elements
  t    # Pop and print top of stack
]      # End of while loop

05AB1E, 4 bytes

'\3Λ

Try it online!

Using the input as length, draw \ in direction 3 (down-right) with the canvas builtin Λ. See Kevin's tip for details on how the canvas works


6 bytes without the canvas builtin:

'\ILj»

Try it online!

For each number in the range IL == [1..input], pad the string "\" with leading spaces to this length (j). » joins the results by newlines.

Another 6 bytes solution suggested by Kevin Cruijssen:

L<'\ú»

Try it online!

For each number in the range L< == [0..input-1], pad the string "\" with that many leading spaces.

Raku, 22 bytes

{[~] (' 'Xx^$_)X~'\
'}

Try it online!

' ' Xx ^$_ generates a list of the spaces starting each line. X~ '\␤' appends a backslash and newline to each of those strings, then [~] concatenates them.

convey, 46 bytes

[0>>,+1
   v"^
{,"=@#]}
 >^}"~v#'\\'
' '!""~/}

Try it online!

Visualization (i use '_' instead of space because the gif doesnt show the space char if i use it, but in the official page the output works whit spaces):

enter image description here

Lolwho.Cares, 183 bytes

* >2,*1210+10 0*+ 0>,02001*101v
                   ^ 010121   <
  ^           121021<
    >*+102021**+vv             <
v 120210021`1012<   +**120021 <
>*101*10102 2012 >*1012+201020`^

Given a decimal number N, will output a line of length N.

Explanation:

* >2,*1210+10 0*+ 0>,02001*101v
                   ^ 010121   <
  ^           121021<

This code reads from the input, and converts ascii decimal to a number. Side effect of it's working means it pushes N, followed by 0.

It does so by first reading a character, finishing when it read 0 (EOF). It then multiplies the current number by 10, and finally it subtracts 48 from the ASCII value and adds.

    >*+102021**+vv             <
v 120210021`1012<   +**120021 <
>*101*10102 2012 >*1012+201020`^

This code takes [N, 0] pushed by the other function and draws a line accordingly. This makes use of the fact that the stack is "initialised" with an infinite amount of 0s at the bottom.

This is basically an implementation of nested for loops; It checks whether enough lines have been printed, then prints X spaces, followed by \ and newline.

The language is a custom esoteric programming language, similar to BEFUNGE (as user pointed out here).

Note: Due to the implementation of number reading, care must be taken to omit any non-decimal characters, including leading/trailing spacing/newlines.

Online interpreter

C (clang), 90 77 60 bytes

i;main(n){for(scanf("%i",&n);i<n;printf("%*s\\\n",i++,""));}

Try it online!

My first work without int in it while still using it. I'm doing better now, aren't I?

Thanks to att for golfing 13 bytes. Thanks to ceilingcat for golfing 17 bytes.

AWK, 34 bytes

{for(;$1--;x=x" ")y=y x"\\\n"}$0=y

Try it online!

This is pretty straightforward I suppose... Each time through the loop creates a string corresponding to one line of output. The control just counts decrements the first commandline argument until it's 0.

 for(;$1--;      )

The body of the loop appends the current output line to an accumulator variables, taking the current "padding" of blanks and appending \ and '\n` to it.

                  y=y x"\\\n"

The "end of loop" expression builds up the padding variable.

           x=x" "

Then once all the lines have been generated, assigning that output string to $0 as a truthy test, without an action, causes the output to be printed.

                               $0=y

Ly, 24 bytes

0(10)'\<n[>&:[o]p' <1-]<

Try it online!

This is really a translation of the approach, just in Ly. So I'm not adding a separate entry for it.

The first task is to push a null terminated string \\n onto the stack.

0(10)'\

Then shift to a new stack and read in the number of lines.

       <n

The construct to loop that many times shifts between stacks a decrements the top of the stack with the loop counter until it hits 0.

         [>        <1-]

The body of the loop, duplicates the stack with the output string on top of itself &: then prints up to the first \0, deletes that null and adds a space. So each iteration prints the current line and appends a space to the front in anticipation of the next iteration.

           &:[o]p' 

When the loop ends and all the lines have been printed, we just need to switch stacks to avoid printing what's left.

                       <

Ruby, 31 Bytes

gets.to_i.times{|i|p' '*i+'\\'}

Works in much the same way as the example code but more rubified

Julia 1.0, 26 21 bytes

thanks dingledooper for challenging my answer

!n=" ".^(0:~-n).*"\\"

Try it online!

C (clang), 37 bytes

f(n){printf("%*c\n",n--,92,n&&f(n));}

Try it online!


C (gcc), 39 bytes

A recursive version suggested by @att.

f(n){--n&&f(n);printf("%*c\n",n+1,92);}

Try it online!


C (gcc), 44 bytes

i;f(n){for(i=0;i++<n;)printf("%*c\n",i,92);}

Try it online!

BQN, 12 bytesSBCS

↕⌽⁼⎉0‿1↑⟜"\"

Try it here.

↕⌽⁼⎉0‿1↑⟜"\" # tacit function which takes an int and returns a character array
       ↑⟜"\" # take input number of characters from the string "\", padding with spaces
 ⌽⁼          # rotate-inverse (right instead of left),
   ⎉0‿1      #   rank 0‿1 (each scalar on the left pairs with a vector on the right)
↕            # by the indices 0 ... input

Stax, 3 bytes

■♦9

Run and debug it

Explanation

m'\)
m    map 1..n and print with newlines
 '\) pad \ on the left with spaces to given length

Ruby, 41 bytes

puts Array.new(gets.to_i){|i|(' '*i+'\\')}

Try it online!

Zephyr, 80 bytes

set s to" "
input n as Integer
for i from 1 to n
print s+"\"
set s to s+" "
next

Try it online!

Perl 5, 34 bytes

s//\\/;$==<>;s// / while(say,$=--)

Try it online!

This should be run from the command line like perl -E 's//\\/;$==<>;s// / while(say,$=--)' to activate the say feature without adding any bytes.

Ungolfed:

$_='\\'; #Set the default variable $_ to a single backslash
$==<>; #Take input into $=. This variable converts the input to an integer
while($=--){ #Decrement $= and loop
    say; #Prints $_ and a newline
    $_=" $_"; #Adds a space to the start of $_
}

Uses s// / as shorthand for $_=" $_" (i.e. to prepend a space to $_). Putting say into the while loop lets us drop the brackets from the loop body.

Factor, 40 bytes

[ iota [ [ bl ] times "\\"print ] each ]

Try it online!

MATLAB/Octave, 32 31 bytes

-1 byte thanks to Luis Mendo

disp([60*eye(input(''))+32,''])

Try it online!
Reads the length from standard input, writes to standard output.
Makes use of identity matrix eye(x).


Alternatively, using function input/output, 22 21 bytes:

@(x)[60*eye(x)+32,'']

Try it online!
Anonymous function, outputs character array.

Bash, 39

printf %*s\\n $(eval echo {1..$1}\\ \\)

Try it online!

PHP, 58 57 bytes

for($i=0;$i<$argv[1];$i++)echo str_repeat(' ',$i)."\\\n";

Try it here!

This is my first golf, so feel free to mention anything I can do to improve this!

R, 42, 39 bytes

write(strrep("\\",diag(x<-scan())),1,x)

Try it online!

Explanation:

R, 35 bytes

cat(sep="\\
",strrep(" ",0:scan()))

Try it online!

CJam, 10 bytes

ri{S*'\N}%

Try it online!

Explanation

r             e# Read input
 i            e# Evaluate as an integer, n
  {     }%    e# Do the following for each k in [0 1 ... n-1]
              e# Push k (implicit)
   S          e# Push space
    *         e# Repeat. Gives a string with k spaces
     '\       e# Push character "\"
       N      e# Push newline
              e# Output the stack (implicit)

Java, 56 bytes

n->{for(var s="\\";n-->0;s=" "+s)System.out.println(s);}

Try it online!

PowerShell, 25 bytes

1..$args[0]|%{' '*$_+'\'}

Try it online!

thats why i love powershell

Red, 30 bytes

repeat i n[print pad/left"\"i]

Try it online!

Python 3, 42 bytes

f=lambda n,s="\\\n":n*s and s+f(n-1,' '+s)

Try it online!

-2 bytes thanks to @ovs

Japt -R, 5 bytes

õ!ù'\

Try it

õ!ù'\     :Implicit input of integer
õ         :Range [1,input]
 !ù'\     :For each, left pad "\" to that length with spaces
          :Implicit output joined with newlines

Japt -mR, 5 bytes

'\iUç

Try it

'\iUç     :Implicit map of each U in the range [0,input)
'\i       :Prepend to "\"
   Uç     :  Space repeated U times
          :Implicit output joined with newlines

Vyxal jṀ, 4 bytes

ƛ\\꘍

Try it Online!

Flags go brrr

ƛ\\꘍   Full Program
ƛ      For each (implicity loops from 0 to n - 1)
 \\    push '\'
   ꘍   prepend x spaces to '\'

is equivalent to mM, which makes implicit range start at 0 instead of 1 and end at n - 1 instead of n.

j joins the top of the stack on newlines at the end.

Canvas, 1 byte

Better tool for the job ;)

Try it here!

Given an integer, this draws a diagonal of that string. If you pass a string instead, this prints the string along the diagonal. There is matching anti-diagonal builtin as well.

Vyxal j, 6 bytes

ʁð*\\+

Try it Online!

ʁð*\\+    
ʁ         Push range(input)
  *       Repeat...
 ð        the string ' ' that many times for each
   \\+    Append a backslash to each

j flag: join on newlines

Retina 0.8.2, 13 bytes

.+
$* 
 
$`\¶

Try it online! Note: Trailing spaces on lines 2 and 3. Explanation:

.+
$* 

Convert the input to a string of spaces.

 
$`\¶

Output each prefix of the string followed by a \, on its own line.

This program outputs two trailing newlines, one from the code, one from Retina 0.8.2's default output. The latter can be suppressed at a cost of 2 bytes by changing the third line to \` . Alternatively the following 14-byte Retina 1 program outputs no trailing newlines:

.+
* 
L$` 
$`\

Try it online! Note: Trailing spaces on lines 2 and 3. Explanation: Much like the Retina 0.8.2 program, except the repetition operator is simply * and the list matches command only inserts newlines between the substitutions.

Python 2, 37 bytes

x='\\'
exec'print x;x=" "+x;'*input()

Try it online!

JavaScript (ES6), 33 bytes

f=(n,s=`\\
`)=>--n?s+f(n,' '+s):s

Try it online!

APL (Dyalog Unicode), 9 bytes (SBCS)

Anonymous tacit prefix function. Returns a list of string, as per meta consensus.

'\'↑⍨¨-∘⍳

Try it online!

∘⍳ indices one through \$n\$, then:

- negate those

¨ for each:

↑⍨ take (when negative: from the rear) that many characters (padding with spaces) from:

  '\' the backslash character

J, 10 bytes

' \'{~=@i.

Try it online!

Jelly, 7 bytes

=þị⁾\ Y

Try it online!

Ḷ⁶ẋp”\Y

Try it online!

How they work

=þị⁾\ Y - Main link. Takes N on the left
=þ      - Yield the identity matrix of size N
  ị⁾\   - Index into "\ ", replacing 1 with "\" and 0 with " "
      Y - Join by newlines

Ḷ⁶ẋp”\Y - Main link. Takes N on the left
Ḷ       - Range [0, ..., N-1]
 ⁶ẋ     - Repeat that many spaces for each
   p”\  - Append "\" to each
      Y - Join by newlines

Jelly, 7 bytes

Ṭ€ị⁾\ Y

Try it online!

Working on golfing. This is longer than I remember it being possible. The JHT exercise allows other characters so I can't get this to 5 bytes because of that :/

Ṭ€ị⁾\ Y    Main Link
 €         For each (implicit range)
Ṭ          Generate a boolean list with 1s at the indices
  ị        Index that into
   ⁾\      "\ "
      Y    and join on newlines

Charcoal, 2 bytes

↖N

Try it online!

right tool for the job

Python 3.8 (pre-release), 46 bytes

for i in range(int(input())):print(' '*i+'\\')

Try it online!