g | x | w | all
Bytes Lang Time Link
076Regenerate210627T014032ZDLosc
276batch210430T052451ZT3RR0R
031Japt R210628T085717ZShaggy
026Vyxal j210628T024820Zwasif
114Excel210502T012859ZAxuary
069Julia210127T142600ZMarcMush
068GolfScript210301T181038ZSamuel W
119Zsh commit 2a96748210123T184557Zpxeger
121JavaScript Node.js210123T211710ZAlex bri
172Wolfram Language Mathematica210131T180228ZBroken P
022Canvas210124T021905ZRazetime
136Java 11210125T081443ZKevin Cr
088PowerShell210126T103336Zmazzy
116PHP210126T093923ZKaddath
027Stax210126T012420Zrecursiv
071Perl 5 + M5.10.0 pa210125T204106ZDom Hast
030Jelly210125T125927ZJonathan
130C gcc210124T100340ZNoodle9
02605AB1E210123T223810Zovs
092Python 3.8 prerelease210123T190437Zpxeger
122Lua LuaJIT210124T153026ZLuaNoob
078Ruby210124T104549ZLevel Ri
069K ngn/k210124T025557Zcoltim
081Python 2210123T201035Zxnor
037Jelly210123T192235ZAdam
032Charcoal210123T175415ZNeil

Regenerate, 84 76 bytes

(( {#2-1}| {$~1-1})(//$3|)(^L){$~1}
){$~1}(( $6|)\\{#3-2*#6}( "){$~1}
){$~1}

Takes the size as a command-line input. Attempt This Online!

Explanation

Spaces are replaced with underscores and newlines with ¶ for improved visibility.

Top half:

(( {#2-1}| {$~1-1})(//$3|)(^L){$~1}¶){$~1}
(                                   )       Group 1: one row of the top half
 (                )                          Group 2: leading spaces
  _{#2-1}                                     Either one less space than the previous row
         |_{$~1-1}                            or (input-1) spaces if this is the first row
                   (     )                   Group 3: slashes
                    //$3                      Either the previous row's slashes plus two more
                        |                     or empty string if this is the first row
                          (^L)               Group 4: ^L
                              {$~1}          Repeat group 4 (input) times
                                   ¶         Newline
                                     {$~1}  Repeat group 1 (input) times

Bottom half:

(( $6|)\\{#3-2*#6}( "){$~1}¶){$~1}
(                           )       Group 5: one row of the bottom half
 (    )                              Group 6: leading spaces
  _$6                                 Either the previous row's spaces plus one more
     |                                or empty string if this is the first row
       \\{       }                   Backslash repeated this many times:
          #3                          The number of slashes in the last match of group 3
            -2*                       minus two times
               #6                     the number of spaces in the latest match of group 6
                  (_")               Group 8: space-quote
                      {$~1}          Repeat group 8 (input) times
                           ¶         Newline
                             {$~1}  Repeat group 5 (input) times

batch 317 309 301 291 284 bytes 276 bytes

Cls&@Set $=@Set 
%$%/Ah=%1*2,z=0
%$%F=@For /L %%a in (1 1 &%$%P=@^<nul set/p&%$%C= @If ,%%y LEQ %1 
%f:a=y%!h!)Do @(%$%/Aw=%1-z
%F%!w!)Do %P%=ESCC
%F%!z!)Do%C%(%P%=//)Else %P%=\\
%F%%1)Do%C%(%P%=^^L)Else %P%^"=ESCC""
%C:EQ=SS%(%$%/A z+=1)Else%C:,=not %%$%/Az-=1
Echo()

Cube.bat

Notes:

Vt sequence ESCC ('cursor right') is used to get around <nul set /p's inability to output leading spaces.

example output: enter image description here

Japt -R, 31 bytes

Æç'Li^)i'/pXÑÃû
c¡Xd`/\\^ L"`Ãw

Try it

Æç'Li^)i'/pXÑÃû\nc¡Xd`...`Ãw     :Implicit input of integer U
Æ                                :Map each X in the range [0,U)
 ç                               :  U times repeat
  'Li^                           :    "L" prepended with "^"
      )                          :  End repeat
       i                         :  Prepend
        '/p                      :    "/" repeated
           XÑ                    :    X*2 times
             Ã                   :End map
              û                  :centre pad each element with spaces to the length of the longest
               \n                :Reassign to U
                 c               :Concatenate
                  ¡              :  Map each X in U
                   Xd`...`       :    For each pair of characters in the string, replace all occurrences of the first in X with the second
                          Ã      :  End map
                           w     :  Reverse
                                 :Implicit output joined with newlines

Vyxal j, 26 bytes

ʁd\/*m‛^L‛ ""?*ƛw?ẋ;fZvṅøĊ

Try it Online!

Excel, 114 bytes

=LET(x,A1,q,SEQUENCE(2*x),b,q>x,r,IF(b,q-x-1,x-q),REPT(" ",r)&REPT(IF(b,"\\","//"),x-r)&REPT(IF(b,"""""","^L"),x))

Link to Spreadsheet

Julia, 79 73 69 bytes

output is a list of lines

f(N,a=-N+1:0,b=0:N-1)=@.[" "^-a*"//"^b*"^L"^N;" "^b*"\\"^-2a*" \""^N]

Try it online!

GolfScript, 68 bytes

~:i,.-1%]zip.-1%]{{~" "*\["//""\\\\"]0=*+["^L"' "']0=i*+}%1:0;n*}%n*

Try it online!

Its really messy, but it works and I don't really know a better way to do it.

Zsh commit 2a96748, 123 121 119 bytes

alias R=repeat
R "i=a=$1" {s=${(l:--i:)};R b++ s+=//;R a s+=^L;<<<$s}
R a {s=${(l:i++:)};R a-i s+='\\';R a s+=' "';<<<$s}

Try it online!

This specific version fixes a bug that would otherwise require i=a=$1 to be in quotes. TIO doesn't have that version obviously, so the linked one is two bytes longer.

JavaScript (Node.js), 121 bytes

s=>(j=n=>' '[b="repeat"]((a=n>=s)?n-s:s+~n)+(a?"//":"\\\\")[b](a?s*2-n:n+1)+(a?"^L":' "')[b](s)+'\n'+(~n?j(--n):''))(s*2)

Try it online!

Wolfram Language (Mathematica), 172 bytes

(m=MapThread[Join,{DiamondMatrix[#][[1;;#+1,1;;#]],2BoxMatrix[#][[1;;#+1,1;;#+1]]}];Print/@StringJoin@@@(Join[m,4Reverse[m]]/.{0->" ",1->"//",2->"^L",4->"\\\\",8->" \""}))&

Try it online!

Brief explanation:

Construct the upper part m with DiamondMatrix and BoxMatrix:

m = MapThread[Join, {DiamondMatrix[n][[1 ;; n + 1, 1 ;; n]], 2BoxMatrix[n][[1 ;; n + 1, 1 ;; n + 1]]}]

Derive the whole matrix M from m:

M = Join[m, 4*Reverse@m]

you can visualize it with:

MatrixPlot[M, Frame -> None]

when n = 10, it's like this:

when n = 10

Replace each number from the matrix with corresponding string:

M/.{0->" ",1->"//",2->"^L",4->"\\\\",8->" \""}

Convert each row to string and print it:

Print/@StringJoin@@@%

Canvas, 27 22 bytes

{╷2×/×^L⁸×+]:↕vL∙ "╋∔r

Try it here!

Explanation

{|2×/×^L⁸×+]:↕vL∙ "╋∔r
{          ]           map each i from 1 to n:
 |2×                   decrement and double i
    /×                 repeat "/" that many times
      ^L⁸×             repeat "^L" n times
          +            add that to get one line
            :          copy the top half
             ↕         mirror vertically (mirrors characters)
              vL∙" ╋   replace 'vL' with '" '
                    ∔  and add vertically
                     r center the whole art  

Java 11, 148 136 bytes

n->{String r="",t=r;for(int i=n;i-->0;t+=" ")r=t+"//".repeat(i)+"^L".repeat(n)+"\n"+r+t+"\\\\".repeat(i)+" \"".repeat(n)+"\n";return r;}

-12 bytes thanks to @OlivierGrégoire.

Try it online.

Explanation:

n->{                        // Method with integer parameter and String return-type
  String r="",              //  Result-String, starting empty
         t=r;               //  Temp-string, starting empty as well
  for(int i=n;i-->0         //  Loop `i` in the range [input, 0):
      ;                     //    After every iteration:
       t+=" ")              //     Append a space to `t`
    r=...+r+...;            //   Change the result-String to:
                            //    Prepend to the result-String:
      t                     //     The spaces `t`
      +"//".repeat(i)       //     plus '//' repeated `i-1` amount of times
      +"^L".repeat(n)       //     plus '^L' repeated the input amount of times
      +"\n"                 //     plus a newline
                            //    Append to the result-String:
      t                     //     The spaces `t` again
      +"\\\\".repeat(i)     //     plus '\\' repeated `i-1` amount of times
      +" \"".repeat(n)      //     plus ' "' repeated the input amount of times
      +"\n";                //     plus a newline again
  return r;}                //  After the loop, return the result-String

PowerShell, 88 bytes

param($n)$n..1|%{($l=' '*--$_)+'//'*($j=$n-$_-1)+'^L'*$n
$b=,($l+'\\'*$j+' "'*$n)+$b}
$b

Try it online!


PowerShell, 104 102 92 bytes, Alternative

param($n),{$l='//';'^L';$i++}*$n+,{$l='\\';--$i;' "'}*$n|%{.$_}|%{' '*($n-$i-1)+$l*$i+$_*$n}

Try it online!

The script generates the array of scriptblocks and executes its in the same context. Less golfed:

param($n)filter g{' '*($n-$i-1)+$l*$i+$_*$n}
,{$l='//';'^L'|g;$i++}*$n+,{$l='\\';--$i;' "'|g}*$n|%{.$_}

PHP, 134 116 bytes

for($f=str_repeat;$i<$n=$argn;)$s=($t=$f(" ",$i++).$f("//",$n-$i).$f("^L",$n)."
").$s.strtr($t,'/^L','\\ "');echo$s;

Try it online!

Yes, much shorter to build the string..

EDIT: a huge 18 bytes saved thanks to optimization from Dom Hastings

Old version kept just for the fun:

157 bytes

for($f=str_repeat;$i<2*$n=$argn;$s.='//')$i++<$n?printf("%".($n-2+$i)."s%s",$s,$f("^L",$n)."
"):printf("%".(5*$n-$i)."s",$f('\\',4*$n-2*$i).$f(' "',$n)."
");

Try it online!

Here is an infamous PHP answer based on printf. Couldn't think of an uglier looking piece of code for now, but I'll work on it (starting to think it would be better to build the whole string)!

Stax, 27 bytes

ü╚lTà╨ú%Ñ►F↔33j♦ü♂D▄P;L.⌂î↑

Run and debug it

Perl 5 + -M5.10.0 -pa, 71 bytes

say,$\=y'/^L'\ "'r.$/.$\for map$"x("@F"-$_--)."//"x$_."^L"x"@F",1..$_}{

Try it online!

Jelly, 30 bytes

ḶṚżḤƊØ.xⱮ;€3,5ẋ$;ṚḤ$$ị“/\^"L ”

A monadic Link accepting a positive integer which yields a list of lists of characters (a list of lines).

Try it online! (The footer calls the Link and joins the resulting lines with newline characters.)

How?

ḶṚżḤƊØ.xⱮ;€3,5ẋ$;ṚḤ$$ị“/\^"L ” - Link: integer, n    e.g. 3
Ḷ                              - lowered range            [0,1,2]
    Ɗ                          - last three links as a monad - f(that):
 Ṛ                             -   reverse                [2,1,0]
   Ḥ                           -   double                 [0,2,4]
  ż                            -   zip together           [[2,0],[1,2],[0,4]]
        Ɱ                      - map with:
     Ø.                        -   bits                   [0,1]
       x                       -   repeat elements        [[0,0],[0,1,1],[1,1,1,1]]
               $               - last two links as a monad - f(n):
           3,5                 -   three pair five        [3,5]
              ẋ                -   repeat (n times)       [3,5,3,5,3,5]
         ;€                    - concatenate each = x     [[0,0,3,5,3,5,3,5],[0,1,1,3,5,3,5,3,5],[1,1,1,1,3,5,3,5,3,5]]
                    $          - last two links as a monad - f(x):
                   $           -   last two links as a monad - f(x):
                 Ṛ             -     reverse              [[1,1,1,1,3,5,3,5,3,5],[0,1,1,3,5,3,5,3,5],[0,0,3,5,3,5,3,5]]
                  Ḥ            -     double               [[2,2,2,2,6,10,6,10,6,10],[0,2,2,6,10,6,10,6,10],[0,0,6,10,6,10,6,10]]
                ;              -   concatenate            [[0,0,3,5,3,5,3,5],[0,1,1,3,5,3,5,3,5],[1,1,1,1,3,5,3,5,3,5],[2,2,2,2,6,10,6,10,6,10],[0,2,2,6,10,6,10,6,10],[0,0,6,10,6,10,6,10]]
                      “/\^"L ” - list of characters = '/\^"L '
                     ị         - index into (1-indexed & modular, i.e. 10->")
                                                     -> ['  ^L^L^L',
                                                         ' //^L^L^L',
                                                         '////^L^L^L',
                                                         '\\\\ " " "',
                                                         ' \\ " " "',
                                                         '   " " "',
                                                        ]

C (gcc), 160 135 130 bytes

Saved 5 bytes thanks to ceilingcat!!!

p(n,c){for(;n--;)printf(L"\n//\\\\L^ \"  "+c+n%2);}i;t;f(n){for(t=i=1;i;i+=t,t=i>n?i=n,-1:t)p(n-i,9),p(!p(2*n,6-t),p(2*~-i,2-t));}

Try it online!

Explanation (before some golfs)

d;p(n,c){                             // p is a helper function that prints     
                                      // n/2 pairs of chars  
  for(d=0;n--;d^=1)                   // loop n times, flipping d between  
                                      //   0 and 1 each time  
    printf(L"                         // print one char of a pair of 
                                      //   chars based on c (then select the  
                                      //   other one on the next loop as d 
                                      //   flips between 0 and 1):  
             //                       //   c==0: '//'  
               \\\\                   //   c==2: '\\'  
                   ^L                 //   c==4: '^L'  
                      \"              //   c==6: '" '  
                                      //   c==7: any number of spaces
                          \n"         //   c==9: p(1,9) prints a newline  
             +c+d);                   // use c and d to select char
}                                     // returns 0 
i;t;f(n){                             // f is the main function    
  for(t=i=1;                          // main loop i goes from 1 to n and  
                                      // back down to 1 again  
    i;                                // loop until i is 0  
    i+=t,                             // bump i up for 1st half and then  
                                      // bump i down for 2nd half  
         t=i>n?i=n,-1:t)              // flip t from 1 to -1 half way thru  
               p(n-i,7),              // print leading spaces   
               p(2*~-i,1-t),          // print left side slashes   
               p(2*n,5-t),            // print right side of cube   
               p(1,9);                // print newline
}                                     //  

05AB1E, 28 26 bytes

-2 bytes thanks to Kevin Cruijssen!

Without this bug, »∊¶¡ could be just .

L<·'/×»∊¶¡„^L„ "‚I×Iδи˜ø.c

Try it online!

Commented:

L<·'/×»∊¶¡      # generate the left part
L               # push the range [1..n]
 <              # decrement to get [0..n-1]
  ·             # double each value: [0, 2, ..., 2*(n-1)]
   '/           # push the string '/'
     ×          # for each number in the list, repeat the string this many times
      »∊¶¡      # vertically mirror to get lower left half

„^L„ "‚I×Iδи˜   # generate the right part
„^L             # push the string '^L'
   „ "          # push the string ' "'
      ‚         # pair into a list: ['^L', ' "']
       I×       # repeat each string input times 
         Iδи    # for each string create a list containing the string input times
            ˜   # flatten into a single list

 ø              # zip both parts to get the rows
   .c           # join each row, centralize and join by newlines

Try it with step-by-step output!

Some slightly longer alternatives:

L<·'/×»∊¶¡εNI@i„ "ë„^L}I׫}.c
L<·'/×»∊¶¡ε„^LNI@i„ "}I×yì}.c
L<·Â«εNI@i'\ׄ "ë'/ׄ^L}I׫}.c

Python 3.8 (pre-release), 97 93 92 bytes

lambda a:sum(zip(*((' '*(x:=a+~i)+'//'*i+'^L'*a,' '*i+r'\\'*x+' "'*a)for i in range(a))),())

Try it online!

Output is a tuple of lines.

-4 by @Seb

-1 by @Danis

Lua (LuaJIT), 122 bytes

r=n.rep;for i=1,n*2 do print(i<=n+0 and r(' ',n-i)..r("/",i*2-2)..r('^L',n)or r(' ',i-1-n)..r("\\\\",n*2-i)..r(' "',n))end

Try it online!

(Above code abuses the TIO's input string-type to save 1 byte, see Not abused version)

Ruby, 78 bytes

->n{puts (0...n).map{|i|puts ' '*(j=n+~i)+?/*i*2+'^L'*n;' '*i+?\\*j*2+' "'*n}}

Builds an array for the bottom half while printing the top half, then dumps the bottom half at the end. I also tried recursion but it was longer.

Try it online!

K (ngn/k), 69 bytes

{` 0:,/',/$(`" "`"//"`"^L";`" "`"\\\\"`" \"")@'&''(t;|t:+(|!x;!x;x))}

Try it online!

Not a great fit for the language, but an interesting exercise...

Python 2, 81 bytes

k=n=input()
while 1:k-=1;i=k^k/n;print' '*i+(n+~i)*2*'\/'[k/n-1]+'^ L"'[k<0::2]*n

Try it online!

Reuses some ideas from my answer on Draw an ASCII hexagon of side length n, including using the index k/n-1 both to select between / and \ in an order where the \ doesn't need escaping, as well as to terminate the loop with error at the end.

Jelly, 37 bytes

Ḷ,Ṛ$ạ’;,ʋ³ẋ@"ɗ€"“ “//“^L”,“ “\\“ "”ẎY

Try it online!

Charcoal, 42 32 bytes

NθG⌈⊖θ\↓‖C‖M↑Fθ«P×^Lθ↘»Fθ«P×" θ↙

Try it online! Link is to verbose version of code. Explanation:

Nθ

Input the size.

G⌈⊖θ\↓

Print a small triangle of \s.

‖C‖M↑

Reflect it twice, once horizontally to complete the bottom left block of \s, once vertically with mirroring to produce the top left block of /s.

Fθ«P×^Lθ↘»

Print the top right block of ^s and Ls.

Fθ«P×" θ↙

Print the bottom right block of "s and spaces.