New answers tagged

1

Python 3, 336 bytes def f(n): N=n+n;R=[*range(3*n)] L = [f'/{i*" "}\\' for i in R[:N]] + [f'\\{2*(N+~i)*"_ "[i+1<n]}/' for i in R[:n]] + [f'|{" "*~-n}|']*8*n + [ f'/{"|"+2*~-n*"_ "[i+1<3*n]+"|":^{2*min(i,N-1)+N}}\\' for i in R ] + ["/"*(i+1<N)+f'/{" "*(n+i)}\\'....


2

Stax, 14 bytes ╬^û╗i§║╜P◙ƒ═½\ Run and debug it Similar to the Jelly answer.


2

PowerShell Core, 155 99 bytes param($a)($r=0..($l=$a.length-2)|%{" "*$_+(,$a[$_]*3-join" "*($l-$_))}) $a+-join$a[$l..0] $r[$l..0] Try it online! 56 bytes saved thanks to @mazzy! Explanation # Build an array containing the top of the star ($r=0..($l=$a.length-2)|%{" "*$_+(,$a[$_]*3-join" "*($l-$_))}) # Prints the ...


1

Jelly, 19 bytes Ỵz⁶UµOHØ^ṙaf⁶;`$)€G Try it online! While I was writing this, it tormented me to no end that the whole mess with af⁶;`$ could just be «, if the codepoint of backslash were somewhere closer to the ballpark of its forward companion. This can definitely be golfed further. Ỵ Split the input on newlines. z⁶ ...


1

Stax, 19 bytes Ǻòî@f┬U☺≥•:Γ_ƒ←⌠Φô Run and debug it


0

Vyxal, 46 bytes (\\n›↳⁰↲\|\/n›↲⁰↳Ṡ,)\O-?-,(\/n›↲⁰↳\|\\n›↳⁰↲Ṡ,) Try it Online! A mess that I can't be bothered fixing, at least for now.


0

Vyxal, 45 bytes ȧDk/ðp*ð+⅛\/w$‹ẋf\Op\OJṄððdV⅛k\ðp*⅛¾?0<ßÞTvṅ⁋ Try it Online! Transposing the input yields the vertical version :)


0

Vyxal, 78 bytes ‛ _m*ðp,‛/ øṀ*ðp,` /\\`w$ẋf⁋¶\/V\|p‛ |+…Ṙ…£`\/\\`w$ẋfṄðpǔð₴…ð₴ǔ,¥Ḃ,,`\__/`*ðp, Try it Online! Builds it incrementally. Here's a cool version that makes it a square.


1

Vyxal, 280 bytes d5+\.꘍,d5+\|꘍,(n-d:£\.꘍3n+\]꘍\#nd›*\[3n+\.꘍Ṡ,¥›\\꘍ndd7+\_*\/Ṡ,)\.?3+꘍\]\#?d›*\[?3+\.꘍Ṡ,ð\\?›\_*\]?2-1∴\#*\.?d‹5∵-\.?2-1∴\#*\[?›\_*\/Ṡ,3<[⟨0|⟨3⟩|⟨2|1⟩⟩$i|3/⌊d2w$ẋf`013`?3%iIJ';]\_*Ṅðpð+ð\|Vðdp:£3?∵꘍øm,¥3?∵\_*+øm,4<[3+|d]\#*:£ðdp\/\_?d‹5∵*\\¥Ṡ,¥L›\|꘍\_?d‹5∵⇧*\|Ṡ,¥L\/꘍\_?d‹5∵4+*\\Ṡ, Try it Online! No, I'm not explaining this.


2

APL(Dyalog Unicode), 4629 bytes SBCS {⍉1↓⍉⊃,/⍵⍴⊂(⍵+⍵-1)3⍴'| +--'} Try it on APLgolf! saved 17 thanks to @Razetime tips! (⍵+⍵-1)3⍴'| +--' we build the entire column e.g. | +-- | +-- | Then : ⍵⍴⊂ ⍝ n copies of that column ,/ ⍝ concatenate ⊃ ⍝ disclose ⍉1↓⍉ ⍝ transpose, drop line, re transpose


6

Charcoal, 88 bytes ↓§θ⁰⊞υ⁺E³¦⁰θFυ«≔¬§ι⁰ηFΦι›λ³«≔§κ⁰ζ≔§Φζ№§ι³λ⁰εJ§ι¹§ι²M⌕§ι³ε✳⁻⁶§ι⁰M⌕ζε✳⁻²η⊞υ⁺⟦ηⅈⅉ⟧κ✳⁻⁶ηζ≦±η Try it online! Link is to verbose version of code. Explanation: ↓§θ⁰ Print the first word vertically. ⊞υ⁺E³¦⁰θFυ« Start a breadth-first traversal of the tree, but prefixing three status variables to each entry for the coordinates and the direction. ≔...


4

Charcoal, 45 bytes FLθ«↑⊖§θι§ηι↙↓⊖§θι↗»J⊖Σ…η⊕汧θζ↗oooW∧⊖ⅉ¬℅KK↘o Try it online! Takes as input an array of heights, an array of widths, and a 0-indexed building. Explanation: FLθ« Loop over each building. ↑⊖§θι Draw the left wall. §ηι↙ Draw the roof. ↓⊖§θι↗ Draw the right wall. »J⊖Σ…η⊕汧θζ Jump to the corner of the building. ↗ooo Print the leap. W∧⊖ⅉ¬...


3

J, 34 bytes '| +-'{~<:@+:$#:@6(,:+&2)@$~*&3-1: Try it online! Consider 3 as input: #:@6...$~*&3-1: Six in binary #:@6 expands to 1 1 0 and "input times 3 minus 1" is 8 *&3-1:, so we extend 1 1 0 that far: 1 1 0 1 1 0 1 1 (,:+&2)@ Stack that with 2 added to itself: 1 1 0 1 1 0 1 1 3 3 2 3 3 2 3 3 <:@+:$ Now extend that ...


4

Haskell, 42 bytes n%a=tail$[1..n]>>a f n=n%[n%"+--",n%"| "] Try it online! Defines f :: Integer -> [String]. [1..n]>>a means: for each element of [1..n], cycle through all elements of a. Then, tail removes the first one. So 3%"+--" evaluates to "--+--+--". % does double duty, first acting on Strings ...


1

Knight, 21 bytes ;=y+0P W=xP O*"#"^yLx Try it online! Had to actually fix a bug in the interpreter on this one. Delimiter is newline, filler is # (although it doesn't check this, it just checks the length) # read base, coerce to int ; = base + 0 PROMPT # read all lines : WHILE (= line PROMPT) # output base ^ length(line) #'s OUTPUT(* &...


3

Python 2 or 3, 49 46 42 bytes -4 bytes thanks to dingledooper lambda n:([("+--"*n)[1:]," |"*~-n]*n)[1:] Returns a list of lines. Try it online! Explanation It's easy to generate this grid: +--+--+-- | | | +--+--+-- | | | +--+--+-- | | | Then we can trim off the first line as well as the first character of each line. Since ...


5

Ruby, 37 bytes ->n{[' |'*~-n]*n*" #{['--']*n*?+} "} Try it online! Ruby, 37 bytes A very similar approach, also 37 bytes: ->n{[' |'*~-n]*n*" #{'--+'*~-n}-- "} Try it online!


8

Python 3, 49 bytes lambda n:f'\n{"--+"*~-n}--\n'.join([' |'*~-n]*n) Try it online!


5

Pip -l, 28 24 23 bytes @>*@>:["+--""| "]XaRLa Try it online! Explanation Same idea as my Python answer, implemented a bit more directly: ["+--""| "] List of two strings Xa Repeat each string n times RLa Repeat the whole list n times @>: ...


4

C (clang), 71 bytes l;f(n){for(l=n*3,n=n*2*l-l;--n;)putchar(n%l?"| +--"[n/l%2*3+n%3]:10);} Try it online! l=n*3 line length (\n included) n=n*2*l-l total characters count for(..;--n) while we iterate backwards : n%l?..:10 > put a return at end of line or.. "| +--"[n/l%2*3+n%3] > take the proper char to put


5

Excel, 62 bytes =LEFT(REPT(IF(MOD(SEQUENCE(2*A1-1),2)," |","--+"),A1),3*A1-1) With gridlines turned off, it looks the same as the single string with line feeds.


2

JavaScript (Node.js), 93 bytes n=>(' |'[r='repeat'](--n)+' 0')[r](n+1).slice(0,-1).split(0).join('\n'+'--+'[r](n)+'--\n'); Try it online!


2

Ruby, 46 bytes ->n{(2..n*2).map{|x|[" -"[x%=2]*2]*n*"|+"[x]}} Try it online!


2

Retina 0.8.2, 43 bytes .+ $* 1 $_¶$_¶ 1 +-- T`-+` |`¶.+¶ 1A` %`^. Try it online! Explanation: .+ $* Convert to unary. 1 $_¶$_¶ Create 2n rows of n 1s. 1 +-- Replace each 1 with +--. T`-+` |`¶.+¶ Change those to | on alternate lines. 1A` Delete the first line of --+s. %`^. Delete the leading +s or |s on each line.


7

Python 3, 70 62 60 58 bytes lambda n:f"-{'-+-'*~-n}-\n".join([f" {' | '*~-n} \n"]*n) Thanks to @Underslash, @Jonathan Allan for removing 4 bytes.


6

Vyxal rj, 15 bytes `+--| `½*ẋfḢvḢ Try it Online! Port of hyper-neutrino's Jelly answer


7

JavaScript (ES6),  67  66 bytes Recursive. f=(n,k=n*2*(n*=3)-n)=>k--?` -|+ `[k%n?~-k%n%3&2|k/n&1:4]+f(n,k):'' Try it online! JavaScript (ES6),  61  58 bytes Saved 3 bytes thanks to @EliteDaMyth The straightforward way. n=>`${s=' |'[R='repeat'](--n)} ${'--+'[R](n)}-- `[R](n)+s Try it online!


5

Vyxal j, 19 bytes :`+--``| `"*$ẋfḢvḢ Try it Online! Ports my Jelly answer. I'll stop for a bit to give other people time to answer. :`+--``| `"*$ẋfḢvḢ Full Program : Duplicate X `+--` Push "+--" `| ` Push "| " " Pair into ["+--", "| &...


6

Charcoal, 16 bytes UO⊖׳N⊖⊗θ |¶--+ Try it online! Link is to verbose version of code. Explanation: UO Draw a rectangle... ⊖׳N ... width 3n-1... ⊖⊗θ ... height 2n-1... |¶--+ ... filled with | and --+ on alternate lines.


5

Jelly, 14 bytes “+--“| ”ẋḊ¥⁺€ Try it online! -2 bytes thanks to Jonathan Allan Returns a matrix of characters. “+--“| ”ẋḊ¥⁺€ Main Link “+--“| ” ["+--", "| "] ¥ Apply last two to a list and X ẋ Repeat the list X times Ḋ Remove the first element € To each row, ⁺ ...


1

Excel, 24 bytes =REPT("#",A1^LEN(A2:A5)) A1 is the base A2:A5 are the input lines


1

Pip -rl, 9 bytes 0XaE#*@>g Try it here! Or, here's a 10-byte equivalent in Pip Classic: Try it online! Takes the base followed by the bar graph (using any non-whitespace symbol) from stdin; outputs a bar graph of 0s to stdout. If you're going to try it on Replit, I suggest using the -e flag to specify the code on the command-line; you'll need to ...


0

Deadfish~, 558 bytes {iiii}iiicii{ccc}ccccddc{ddd}c{{i}i}ic{ddd}ddddddccccc{dddddd}iiii{cc}ccccccccc{{i}d}iicd{{d}d}c{{i}i}ic{ddd}ddddddcccccccc{dddddd}iiii{cc}cccccc{{i}d}iicd{{d}d}c{{i}i}ic{ddd}ddddddccccccccc{dddd}ddd{cc}ccccc{{i}dd}dcd{{d}d}c{{i}i}ic{ddd}dddddd{c}c{dddddd}iiii{cc}ccc{{i}d}iicd{{d}d}c{{i}i}ic{ddd}dddddd{c}c{dddddd}iiii{cc}ccc{{i}d}iicd{{d}...


0

Stax, 8 bytes ÇÉ⌐öç♦}k Run and debug it Explanation mzsE|r'-& m map each pair and print with newline z empty string s swap with pair E|r convert to range '- - character & assign at indices(extends the empty string with spaces)


1

Vyxal j, 9 bytes ƛ÷ε\-*nt↳ Try it Online! Expects a list of lists. ƛ # Map each pair to... ÷ε # Their difference \-* # -s nt↳ # Padded to the length of the second.


1

Vyxal j, 41 bytes »'ꜝ»12τƛ\X*34↲n9=[ð\-V\+|\|]+\|p;\+17-mpm Try it Online! 12τ # Base-12 digits of... »'ꜝ» # 9119 (so 5,8,9,11) ƛ ; # Mapped to... \X* # That many Xs 34↲ #...


1

Vyxal Dj, 12 bytes ‛↑↓3**3ẇÞTvṅ Try it Online! ‛↑↓ # String `↑↓` 3* # Times 3 * # Times input 3ẇ # Chunks of 3 ÞT # Transpose vṅ # Join each # Join by newlines


2

Vyxal jar, 28 bytes vLG↲ÞTƛƛk<1꘍ḟ3` /\\\/`/i;ṘṄ Try it Online! The bit at the start pads each line as necessary to make it a rectangle.


1

Vyxal, 52 bytes (x|`+--`*\++,2(⁰(n←x+₂[`| `|`|##`]₴)\|,))`+--`*\++, Try it Online! A. Big. Mess.


1

Vyxal j, 15 bytes ×d?(‛ ()‛/_WvøṀ Try it Online! Example output: **** () () () () /__\ I kinda golfed the shade. ×d # two asterisks ?( ) # Input times... ‛ ( # Push the two-char ` (` ‛/_ # Push the two-char `/_` W # Push the entire stack vøṀ # Ascii-art mirror each item.


2

Julia, 22 bytes x$b="#".^b.^length.(x) Try it online! input and output are lists of strings


1

Jelly, 6 bytes ẈƓ*ṁ@" Try it online! Takes a list of lines on the left and the base on STDIN How it works ẈƓ*ṁ@" - Main link. Takes a list of lines L on the left Ẉ - Get the lengths of each line Ɠ - Read the base b from STDIN * - Raise b to the power of each length " - For each pair (length, original_line): @ - ...


2

APL (Dyalog Unicode), 7 bytes Anonymous tacit infix function taking base as left argument and list of strings as right argument *∘≢¨⍴¨⊢ Try it online! *∘≢¨ base to the power of the length of each string ⍴¨ cyclically reshapes each ⊢ string


2

Risky, 6 bytes _?_!?_?[*+? Try it online! Inputs and outputs an array like ["@@", "@@@@"]. Unfortunately, the output is implicitly concatenated. 6 more bytes to have it joined by newlines: Risky, 12 bytes _*+_0+_0+_0*_?_!?_?[*+? Try it online!


1

Vyxal, 128 bytes d(\/n꘍⁰3*↳øṀ,)(⁰n+\\꘍⁰d‹n- n⁰‹=[\_|ð]*+øṀ,)8*(⁰d\|꘍⁰‹꘍m,)d(\/n꘍⁰d↳\|+⁰‹꘍øṀ,)(\/⁰d↲\|+n⁰‹=[\_|ð]⁰‹*+øṀ,)d(\/n꘍⁰d‹↳:L⁰d≠[\/p]⁰꘍øṀ, Try it Online! Generates the rocket bit by bit.


2

Vyxal j, 7 bytes ⌈';vL×* Try it Online! Vertical, 17 bytes ⌈';vL:G$×*v↲ÞTṘvṅ Try it Online! Vertical flipped, 16 bytes ⌈';vL:G$×*v↲ÞTvṅ Try it Online!


0

Vyxal, 101 bytes ‛_oƛ` (`pøṀ22↳,;\/:3-øṀp20↳₴ð,₀`/ | `꘍3\|꘍m+,9`* /\---/\ `꘍,12‛~~꘍3\~꘍m+,`..."`:₴`λɾ λ• mo⋎Þ ¬¾?`₴Ṙ, Try it Online! Uses some form of compression.


1

Vyxal r, 6 bytes ƛL⁰e×* Try it Online! Inputs and outputs a list of strings; uses * as the filler character 'cuz that's easy in Vyxal. ƛL⁰e×* ƛ # For each bar in the string e # Raise... ⁰ # the base... L # to the power of the bar's length ×* # Push that many *s


2

Knight, 41 bytes ;=aP;=nF;W<=n+1nLaO GaFn;OaW=aSa-LaT1""Oa Nothing too fancy, we just print out the first half, then the middle, then the second. ; = a PROMPT # read stdin ; = n FALSE # will coerce to `0` within the `WHILE` condition, but saves us a space from `=n 0` # until we're at the length of `a`, print the prefix [0..n] from `a` ; WHILE ...


3

x86-16 machine code, IBM PC-DOS, 33 bytes Hexdump: 00000000: bf 82 00 91 89 fa e8 0a 00 74 06 41 eb f8 e8 02 .........t.A.... 00000010: 00 e2 fb b4 40 cd 21 b0 0d ae cd 29 b0 0a cd 29 ....@.!....)...) 00000020: c3 . Commented assembly: [org 0x100] start: ; DI <- first command line argument ...


Top 50 recent answers are included