New answers tagged

1

1+, 173 bytes ."11+""*"**;1^<#[#(?|11##11+"1+""*""*+++;1+"\"/<1+1<1+#)]11+"""**+;11+"1+""""*++*+;1^<11++#(|?)[#(|11##11+""*"**;1+"\"/<1+1<1+#)]11+"1+"*""*++;11+"""**+;11+"*"&...


0

R, 74 bytes cat(" ",rep("_",n<-scan()),"\n","/",s<-rep(" ",n),"\\\n","|",s,"|",sep="") Try it online! I hit a dead end trying to golf this at 77 bytes (or even this).


0

C#, 97 bytes string X(int n)=>$@" {R(n,'_')} /{R(n)}\ |{R(n)}|";string R(int n,char c=' ')=>new string(c,n); Try it online!


0

Python 3, 50 bytes lambda x:print(f" {'_'*x}\n/{' '*x}\\\n|{' '*x}|") if returning the string is acceptable instead of printing it it'd be 43 bytes lambda x:f" {'_'*x}\n/{' '*x}\\\n|{' '*x}|"


1

MAWP v1.1, 92 bytes %@_1A84W;[1A~25WWM~]%!![1A92W1M5W;]%67M;85W7M;[1A84W;]%45W3M4W;67M;65W1M4W;[1A84W;]65W1M4W;. Try it!


0

V (vim), 17 bytes Àé_>>o/\Àé ÙÓÓ/| Explain À # @arg times é_ # <M-i>nsert a '_' >> # indent by one space o/\ # insert '/\' on the next line (cursor stays at '\') Àé # @arg times insert ' ' Ù # Duplicate this line down Ó / ...


2

Python 3, 41 bytes lambda n:(f" /|{'_ '*n} \\|\n\n"*3)[::3] Try it online! How could I forget about f-strings? Python 3, 43 bytes lambda n:(" /|%s \\|\n\n"%("_ "*n)*3)[::3] Try it online! Constructs the string transposed, then transposes it using modular arithmetic.


0

Google Sheets, 47 Closing parens/quotes already discounted. Input: A1 A2 to A3: =ArrayFormula(LEN(SPLIT(A1," "))) =A2=COUNTIF(2:2,A2)


1

brainfuck, 174 bytes only works with input from 0 to 9, didn't think about this problem while writing the program ++++[>++++<-]>[->++++++++>+++>++>>>++++++>++++++>+>+++<<<<<<<<<]>---->->>>,>->---->------>[-<<<<->>>>]<<<<<<.>&...


1

Husk, 17 bytes TJR⁰"_ "½" /| ¦| Try it online! Explanation TJR⁰"_ "½" /| ¦| Input is a number, say n = 3, accessed via ⁰. " /| ¦| String literal " /| \|". The parser replaces ¦ by \ and the closing " is implicit. ½ Split in half: x = [" /|", &...


1

MATLAB/Octave, 36 bytes @(n)[' /|';repmat('_ ',n,1);' \|']' Try it online! Simple anonymous function that stitches together the first column ( /|), n middle columns (_ ), and the final column ( \|), then returns the result. Because the strings are rows rather than columns, everything is stitched together vertically, and then the result is transposed to ...


1

Whitespace, 243 bytes [S S S T S T T T S S N _Push_92_|][S S S N _Push_0][S N S _Duplicate_0][T N T T _Read_STDIN_as_integer][T T T _Retrieve_input][N S S N _Create_Label_LOOP1][S N S _Duplicate][N T S S N _If_0_Jump_to_Label_DONE_WITH_LOOP1][S S S T N _Push_1][T S S T _Subtract][S S S N _Push_0_space][S N T _Swap_top_two][N S N ...


1

Retina, 22 bytes .+ $0*_¶/$0* \¶|$0* | Try it online or verify a few more test cases. Pretty straight-forward: convert the input to unary, using that amount of '_' ($0*_) and two times that amount of spaces ($0* ) respectively, surrounded with the rest of the output (leading space on the first line; surrounded with /\ on the second line; and surrounded ...


3

Java 11, 61 bytes n->" "+"_".repeat(n)+"\n/x\\\n|x|".replace("x"," ".repeat(n)) Try it online. Explanation: n-> // Method with integer parameter and String return-type " " // Return a space +"_".repeat(n) // Appended with the input amount ...


1

Perl 5 -p, 32 bytes $#_=$_;$_=$"._ x$_." /@_\\ |@_|" Try it online! Explanation Pretty straightforward, but the first part of this sets the last index of the undefined list @_ to the (implicit from -p) input ($_). $_ is then set to $" (space) followed by $_ _s, a literal newline, then /, and the interpolated empty list @_ that has a ...


0

Ruby, 97 94 bytes puts " "*(a%2)+" ^";f=->n{puts""+["/!\\\n---^"," /!\\\n ^---"][n%2];(n>1)?f[n-1]:puts(" -")} Try It Online! I was unable to find a way to fit the entire thing in one function, so f is set to the lambda. Based on TotallyHuman's Python answer.


3

PowerShell, 43 41 bytes -2 bytes thanks to mazzy param($n)' '+'_'*$n ' '*$n|%{"/$_\ |$_|"} Try it online! Eh, it's okayslightly better Alternative 41 byte solution offered by mazzy


0

05AB1E, 42 bytes É·>'^ú¶•2Ÿ§'vôÅ•"- ^\!/"ÅвJ12ôIL<Rè`„ -J Try it online or verify some more test cases. Minor 42 bytes alternative: É·ðú„^ •e QΣœKΔ•"- ^ \!/"ÅвJ8₂‚£ILRè»… -J Try it online or verify some more test cases. Explanation: É # Check if the (implicit) input-integer is odd (1 if odd; 0 if even) · ...


0

Burlesque, 7 bytes ln)L[sm Try it online! Requires a trailing newline after the input. Technically the trailing newline is only needed if the input ends on a newline (as ln ignores one trailing newline), and it doesn't make a difference whether it's there or not otherwise, but stating it as a blanket requirement is probably preferable. Returns 1 for square ...


2

Perl 5 -p, 40 bytes say$"._ x$_,$/,$_='/'.$"x$_.'\\';y/ /|/c Try it online!


1

PHP, 63 61 60 bytes $a=++$argn;printf("%-'_{$a}s /%{$a}s |%{$a}s",' ','\\','|'); Try it online! printf seemed the optimal way, but I may be wrong.. EDIT: saved 2 bytes with a multiline string EDIT 2: saved another one by init $a before


3

05AB1E, 18 17 bytes …_ ε×… /|NèºSsý, Try it online or verify a few more test cases. Explanation: …_ # Push string "_ " ε # Map over each character in this string: × # Repeat it the (implicit) input amount of times as string … /| # Push string " /|" Nè # ...


2

Haskell, 58 bytes f n|x<-' '<$[1..n]=' ':('_'<$x)++"\n/"++x++"\\\n|"++x++"|" Try it online!


3

Pyth, 24 bytes %" %s /%s\\ |%s|"*RQ"_ Try it online! Explanation %"..."*RQ"_ "_ : The string literal "_ " *RQ : Multiply each element of the string by input (["___", " ", " "]) %"..." : Do string formating on string with args from ...


1

Io, 127 bytes method(x,list(" _ ","/ \\","| |")map(i,list(i at(0)asCharacter,i at(1)asCharacter repeated(x),i at(2)asCharacter)join println)) Try it online!


29

i386 (16-bit mode) Bootsector, 512 bytes All i386 bootsectors have to be 512 bytes, so... Without the padding required by i386, it is 137 bytes. Since I can't easily post a TIO link, here's a screenshot of it running: This code registers the BIOS interrupt int 0x69 to take the number in the bx register and use it as input. Thus, doing mov bx, 3 int 0x69 is ...


3

C (gcc), 72 70 bytes -2 bytes thanks to ceilingcat! f(n){printf(" %s\n/%*c\n|%*2$c",memset(calloc(n,2),95,n),n+1,92,'|');} Try it online!


1

Perl 6, 49 bytes Edit: -4 bytes ->$n {my$s=" "x$n;my$u="_"x$n;" $u\n/$s\\\n|$s|"} Try it online!


2

Scala, 47 bytes n=>print(s" ${"_"*n}\n/${" "*n}\\\n|${" "*n}|") Longer version, 94 bytes n=>print(Seq((' ',' ',"_"),('/','\\'," "),('|','|'," "))map(t=>t._1+t._3*n+t._2)mkString "\n") Try them in Scastie


5

Python 2, 47 bytes lambda n:" %s\n/%s\\\n|%s|"%("_"*n," "*n," "*n) Try it online! Inserting the n-dependent components into a template using string formatting. 48 bytes lambda n:" "+"_"*n+"\n/"+" "*n+"\\\n|"+" "*n+"|" Try it online! Straight up ...


3

Japt, 20 bytes " {ç'_} /{ç}\\ |{ç}| Try it ç is one of Japt's repeat methods for integers; you can probably figure the rest out from there!


1

C (gcc), 75 bytes i;f(n){for(i=-1;n-i++;)putchar(i?95:32);printf("\n/%*c\n|%*c",i,92,i,124);} Try it online!


4

05AB1E, 26 21 bytes My original 26 bytes approach: " 0 /1\|1|"3ô„_ vy¹иJNs:}» Explanation: " 0 /1\|1|"3ô„_ vy¹иJNs:}» " 0 /1\|1|" push string template (the idea is to replace 0 and 1 with _ and space respectively using loop count index 3ô split by chunks of 3 „_ ...


10

Charcoal, 11 bytes ↑|↗/×_N¶\¶| Try it online! Link is to verbose version of code. This shape is too simple to tax Charcoal's drawing primitives, so this is just basically printing strings to the canvas. Explanation: ↑| Print the left | and move the cursor up a line. ↗/ Print the / and move the cursor to the start of the _s. ×_N Print the desired number ...


2

C (gcc), 109 91 bytes Saved a whopping 18 bytes thanks to ceilingcat!!! #define p printf(L"| |\\ / _ "+i) i;j;f(n){for(i=9;i--;i--,p,puts(""))for(i-=p,j=n;j--;)p;} Try it online!


5

Rust, 79 78 76 57 53 bytes -4 bytes thanks to madlaina |n|print!("{:_<n$} {:n$}\\ {:n$}|"," ","/","|",n=n+1) Try it online Old answer (76 bytes): |n|format!(" ")+&"_".repeat(n)+" /"+&" ".repeat(n)+"\\ |"+&" ".repeat(n)+"|" Try it ...


2

Jelly, 19 bytes “_ ”ד “/\“||”j"Y A full program accepting a non-negative integer which prints the resulting ASCII art. Try it online! How? “_ ”ד “/\“||”j"Y - Main Link: integer, n (e.g. 3) “_ ” - list of characters = ['_', ' ', ' '] × - multiply -> ['___', ' ', ' '] (now strings, a bit of a hack in ...


0

Python 3, 57 bytes lambda x:[print(z+y*x+a)for y,z,a in["_ "," /\\"," ||"]] Try it online!


4

MAWP, 95 bytes %@~52WWM52WWM52WWM84W;![1A99M1M5W;]%52W;68W1A;![1A84W;]%68W2W4A;52W;56W1M4W;![1A84W;]%56W1M4W;. Try it! Explanation: % Remove initial 1 from stack @~ Push input as integers and reverse stack 52WWM Add top of stack multiplied by 10 to second stack element [5,4,3,2] ==> [5,4,...


2

MATL, 20 bytes ' /|'4i:)B95*' \|'v! Try it online! How it works ' /|' % Push this string: first column of the output, but as a row (*) 4 % Push 4 i:) % Implicitly input n; range; modular indexing. This gives a row vector % [4 4 ... 4] of length n B % Convert to binary. Each number gives a row in the output. So this % ...


0

Ruby, 57 bytes n=gets.to_i $><<' '+?_*n+" \n/"+' '*n+"\\\n|"+' '*n+'|' Try It Online!


2

JavaScript (ES8), 50 bytes n=>` ${'_'.repeat(n)} /${s=''.padEnd(n)}\\ |${s}|` Try it online! JavaScript (ES6), 50 bytes n=>' '+`_ / \\ | |`.replace(/_| /g,c=>c.repeat(n)) Try it online!


1

Ruby, 36 bytes ->n{" #{?_*n} /#{a=" "*n}\\ |#{a}|"} Try it online!


4

APL (Dyalog Unicode), 21 bytes (SBCS) Full program, prompting for n from stdin. ' /|',' \|',⍨3↑1⎕⍴'_' Try it online! '_' an underscore 1⎕⍴'_' cyclically reshaped into a matrix with one row and n columns 3↑ take the first three rows, padding with spaces ' \|',⍨ append this character-list as a trailing column ' /|', prepend this character-list as a leading ...


4

Integral, 37 31 Bytes ♂8♦⌡_⌡g►⌡/⌡•8g►⌡\⌡►•⌡|⌡♦8g►⌡|⌡► First real answer in my new language! Try it Alternative Explanation: (Implicit input) ♂ Triplicate top of stack 8 Push space ♦ Swap ⌡_⌡ Push underscore g Repeat string ► Concatenate ⌡/⌡ Push slash • Stack: ...abc -> ...bca 8 Push space g Repeat string ► ...


3

Charcoal, 130 bytes FχFχ⊞υ×⁶⎇﹪ι²⁻⁹κκ≔⁻LυNθ≔⁻LυNη≔⊕§υηζ≔׳÷ηχηJ§υθ׳÷θχ F›ζⅈ«≦⊕ζ »F⁻ζ⁺ⅈ⁻ⅉηG←←↑→↘→²_F⁻ⅈ⁺ζ⁻ⅉηG↑←↙→²_W›ⅉη«≔⎇›⁻ⅉη↔⁻ζⅈ²∨›ζⅈ³ιP✳ι¹←←✳ι¹→¿›ⅉη_ Try it online! Link is to verbose version of full 198-byte program that includes drawing the entire background. Explanation: FχFχ⊞υ×⁶⎇﹪ι²⁻⁹κκ Get the X-coordinates of all 100 squares (since each row reverses ...


0

SnakeEx, 38 bytes h:{c<B>1}{c<L>1}{e<>}{e<R>} c:.+$ e:.$ A match is truthy; no match is falsey. Try it here The previous 50-byte SnakeEx submission was copied from the original solution to the detect-square-inputs problem in the 2D pattern-matching language challenge. Here's the thing: that problem says, "Match the entire input ...


4

Python 2, 316 bytes def f(m): r=[list(' '*61)for y in range(31)] (y,x),(b,a)=[[(109-p)/10*3,1+min(p%20,19-p%20)*6]for p in[max(m)-1,min(m)-1]] while y<b:c=cmp(a,x);r[y][x:x+4]=r" /|\___/|\ "[c%3::3];x+=c;y+=1 if x==a:r[y-1][x+2-(r[y-1][x]>' ')]=" " while x-a:c=cmp(a,x)+1;r[y-2][x+c:x+2+c]="__";r[y-1][x+c*3/2]="...


0

Prolog, 99 bytes f([[1,_],[_,1]|_]):- !,0=1. f([[_,1],[1,_]|_]):- !,0=1. f([[1,1]|_]):- !,0=1. f([_|T]):-T==[];f(T). Try it in SWISH xnor's comment that the problem statement was equivalent to checking if no 2 x's touched vertically or diagonally helped me a lot here. Imperfect version (never terminates if false), 66 bytes f([X|T],C):-nth0(C,X,0),(T==[];f(...


6

Pyramid Scheme, 31655 bytes, non-competing (obviously...) So, I thought this would be a funny thing to try. ^ ^ ^ ^ ^ ...


Top 50 recent answers are included