| Bytes | Lang | Time | Link |
|---|---|---|---|
| 076 | Regenerate | 210627T014032Z | DLosc |
| 276 | batch | 210430T052451Z | T3RR0R |
| 031 | Japt R | 210628T085717Z | Shaggy |
| 026 | Vyxal j | 210628T024820Z | wasif |
| 114 | Excel | 210502T012859Z | Axuary |
| 069 | Julia | 210127T142600Z | MarcMush |
| 068 | GolfScript | 210301T181038Z | Samuel W |
| 119 | Zsh commit 2a96748 | 210123T184557Z | pxeger |
| 121 | JavaScript Node.js | 210123T211710Z | Alex bri |
| 172 | Wolfram Language Mathematica | 210131T180228Z | Broken P |
| 022 | Canvas | 210124T021905Z | Razetime |
| 136 | Java 11 | 210125T081443Z | Kevin Cr |
| 088 | PowerShell | 210126T103336Z | mazzy |
| 116 | PHP | 210126T093923Z | Kaddath |
| 027 | Stax | 210126T012420Z | recursiv |
| 071 | Perl 5 + M5.10.0 pa | 210125T204106Z | Dom Hast |
| 030 | Jelly | 210125T125927Z | Jonathan |
| 130 | C gcc | 210124T100340Z | Noodle9 |
| 026 | 05AB1E | 210123T223810Z | ovs |
| 092 | Python 3.8 prerelease | 210123T190437Z | pxeger |
| 122 | Lua LuaJIT | 210124T153026Z | LuaNoob |
| 078 | Ruby | 210124T104549Z | Level Ri |
| 069 | K ngn/k | 210124T025557Z | coltim |
| 081 | Python 2 | 210123T201035Z | xnor |
| 037 | Jelly | 210123T192235Z | Adam |
| 032 | Charcoal | 210123T175415Z | Neil |
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:
- must be run from the command line using:
Echo(cube.bat n|Cmd /V:onwherenis an integer representing cube size and cube.bat is the filename of the file - lines
1and3end wth trailing spaces - requires windows 10 with virtual terminal support
ESCis a stand in for the ANSI escape character, As it can't be pasted here, the scripts raw paste data can be found here.- Or it can be generated by opening the command prompt and typing:
>"%TEMP%\escape.chr" Echo(ALT+027 then pressing ENTER
- Or output using a for loop with
Echo off:(For /F "skip=4 DELIMS=" %a in ('Echo(prompt $E^|cmd')Do Echo(%a) >"%TEMP%\escape.chr"
- Or it can be generated by opening the command prompt and typing:
Vt sequence ESCC ('cursor right') is used to get around <nul set /p's inability to output leading spaces.
Japt -R, 31 bytes
Æç'Li^)i'/pXÑÃû
c¡Xd`/\\^ L"`Ãw
Æç'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
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))
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]
GolfScript, 68 bytes
~:i,.-1%]zip.-1%]{{~" "*\["//""\\\\"]0=*+["^L"' "']0=i*+}%1:0;n*}%n*
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}
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)
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->" \""}))&
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:
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
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.
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
PowerShell, 104 102 92 bytes, Alternative
param($n),{$l='//';'^L';$i++}*$n+,{$l='\\';--$i;' "'}*$n|%{.$_}|%{' '*($n-$i-1)+$l*$i+$_*$n}
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;
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)."
");
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)!
Perl 5 + -M5.10.0 -pa, 71 bytes
say,$\=y'/^L'\ "'r.$/.$\for map$"x("@F"-$_--)."//"x$_."^L"x"@F",1..$_}{
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));}
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
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))),())
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
(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.
K (ngn/k), 69 bytes
{` 0:,/',/$(`" "`"//"`"^L";`" "`"\\\\"`" \"")@'&''(t;|t:+(|!x;!x;x))}
Not a great fit for the language, but an interesting exercise...
(t;|t:+(|!x;!x;x))build a nested list containing the number of copies of each type of symbol to take. (i.e. spaces from x..0,0..x, slashes from 0..x,x..0, and x copies of^Land").&''convert to indices, e.g.3 1 5=>0 0 0 1 2 2 2 2 2(`" "`"//"`"^L";`" "`"\\\\"`" \"")build another nested list (of the same shape), this time containing symbol versions of the output characters. This avoids having to enlist the individual strings and simplifies the list notation a bit. Since they contain special characters (as opposed to being alphanumeric), the contents need to be enclosed in"'s, with"and\also needing to be escaped.(...)@'(...)retrieve the correct number of copies of each type of symbol,/',/$stringify the symbols, and raze them into the lines of the output` 0:print them (this elides the wrapping"s and\escapes otherwise present)
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
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.
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.

