24
\$\begingroup\$

Draw an ASCII-art rainbow!

Input

An integer between 0 and 1000, inclusive.

Examples

Input 0:


/\
||

Input 1:

 _
/ \
| |

Input 2:

 __
/  \
|  |

Input 3:

 ___
/   \
|   |

The first row is a space followed by n underscores.

The second row is a slash followed by n spaces, and a backslash.

The third row is a pipe followed by n spaces, and a pipe.

Trailing spaces are allowed.

This is . Shortest code wins.

\$\endgroup\$
5
  • \$\begingroup\$ May we take input as 0009 or 0561 instead of 9 and 561 if it is less than 1000? \$\endgroup\$
    – Dion
    Commented Aug 3, 2020 at 16:10
  • \$\begingroup\$ @Dion Yes, that is acceptable. \$\endgroup\$
    – nph
    Commented Aug 3, 2020 at 16:11
  • 15
    \$\begingroup\$ I'd call this an arch, not a rainbow \$\endgroup\$ Commented Aug 4, 2020 at 13:05
  • 3
    \$\begingroup\$ @NooneAtAll A rainbow is an arch, isn't it? \$\endgroup\$
    – user96495
    Commented Aug 6, 2020 at 2:24
  • 3
    \$\begingroup\$ it's Π house shaped \$\endgroup\$ Commented Aug 6, 2020 at 16:00

60 Answers 60

31
\$\begingroup\$

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: enter image description here

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 equivalent to the last test case. The disassembled, Intel-syntax source is:

[org 0x7c00]

xor ax, ax
mov es, ax
cli
mov dx, interrupt
mov [es:0x69*4], dx
mov ax, cs
mov [es:0x69*4+2], ax
sti

xor bx, bx
int 0x69
call newline
mov bx, 1
int 0x69
call newline
mov bx, 2
int 0x69
call newline
mov bx, 3
int 0x69
cli
hlt

interrupt:
or bx, bx
jz special
push bx
mov ax, 0x0e20
int 0x10
mov al, '_'
.loop1:
int 0x10
dec bx
jnz .loop1
call newline
mov al, '/'
int 0x10
mov al, ' '
pop bx
push bx
.loop2:
int 0x10
dec bx
jnz .loop2
mov al, '\'
int 0x10
call newline
mov al, '|'
int 0x10
pop bx
mov al, ' '
.loop3:
int 0x10
dec bx
jnz .loop3
mov al, '|'
int 0x10
iret

newline:
mov ax, 0x0e0d
int 0x10
mov al, 0x0a
int 0x10
ret

special:
mov si, s
mov ah, 0x0e
.sloop:
lodsb
int 0x10
or al, al
jnz .sloop
iret

s: db '/', '\', 10, 13, '|', '|'

times 510-($-$$) db 0
dw 0xaa55

(Bit verbose, I know, but hey, it's assembly.)

\$\endgroup\$
10
\$\begingroup\$

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 of _s. This leaves the cursor just to the right of the last _.

¶\¶|

Move down a line, print a \, and print a | directly beneath.

Just for fun I thought I'd write a 25-byte version which allows you to vary the height and thickness too:

NθNηUOηN|↑G→↑η/↗UOθη_‖BOθ

Try it online! Link is to verbose version of code. Takes input as inner width, thickness and inner height. Note that Charcoal does not support zero-sized boxes, so all of the inputs need to be at least 1.

\$\endgroup\$
2
  • \$\begingroup\$ First example is missing the link! I looked at fixing it but I was too tired to realise the lower link was different... \$\endgroup\$ Commented Aug 5, 2020 at 5:33
  • \$\begingroup\$ @DomHastings Thanks, I've edited the link back in now. (Thank goodness for edit history!) \$\endgroup\$
    – Neil
    Commented Aug 5, 2020 at 8:49
7
\$\begingroup\$

Rust, 76 57 53 51 45 bytes

-4 bytes thanks to madlaina

|n|print!(" {:_<1$}
/{0:1$}\\
|{0:1$}|","",n)

Try it online


Old answer (76 bytes):

|n|format!(" ")+&"_".repeat(n)+"
/"+&" ".repeat(n)+"\\
|"+&" ".repeat(n)+"|"

Try it online

Just the boring answer. Borrows are needed to satisfy the type checker, unfortunately.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You can save 4 bytes by leaving out the space and < in the format strings for the spaces, as left-aligned, space-padding is already the default :) \$\endgroup\$
    – madlaina
    Commented Aug 3, 2020 at 18:25
5
\$\begingroup\$

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 column

\$\endgroup\$
5
\$\begingroup\$

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 concatenation.

\$\endgroup\$
1
  • \$\begingroup\$ Outgolfed by @Caagr98. \$\endgroup\$
    – Dingus
    Commented Aug 12, 2020 at 13:53
5
\$\begingroup\$

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
             „_               push 2 chars _ and space
               v        }     for each character in the previous string
                y¹и           repeat it by the number in input
                   J          join the new string
                    Ns        push the index before that string to easily replace
                      :       replace in the string template
                         »    join by new lines

Try It Online

21 bytes (@KevinCruijssen comments):

„_ S×ā" 1/2|2"2ô.º»r‡

Try It Online

\$\endgroup\$
4
  • 1
    \$\begingroup\$ " 0 /1\|1|"3ô can be " 0/1|1"2ô.º for -1. And иJ has a builtin × for another -1. \$\endgroup\$ Commented Aug 4, 2020 at 9:27
  • 1
    \$\begingroup\$ You can also do the » before the loop so you can remove the } for another -1. \$\endgroup\$ Commented Aug 4, 2020 at 9:33
  • 1
    \$\begingroup\$ Taking it one step further, you can remove the loop entirely by using 12 instead of 01 and the builtin ā combined with a transliterate : " 1/2|2"2ô.º»„_ SI×ās‡. Which can be reduced by another byte by using the implicit input with a reverse: „_ S×ā" 1/2|2"2ô.º»r‡ (21 bytes), which still uses your original approach, except without loop. :) PS: I've also posted a 17-byter 05AB1E answer just yet with a different approach. \$\endgroup\$ Commented Aug 4, 2020 at 9:37
  • \$\begingroup\$ Thanks for those great comments :) will edit with your notes. \$\endgroup\$
    – SomoKRoceS
    Commented Aug 4, 2020 at 18:09
5
\$\begingroup\$

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!

\$\endgroup\$
0
5
\$\begingroup\$

MAWP 1.1, 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,23]
52WWM52WWM         Two more times [5,4,3,2] ==> [2345]

84W;               Print a space (8*4=32)

!                  Duplicate top of stack
[                  Start of loop
1A                 Subtract 1
99M1M5W;           Print an underscore ((9+9+1)*5=95)
]                  End of loop. If result from subtraction doesn't 
                   equal to 0 jump to start of loop
%                  Remove 0
52W;               Print a newline (5*2=10)

68W1A;             Print a slash (6*8-1=47)
![1A84W;]%         Do the same loop as before but printing spaces instead
68W2W4A;           Print a backslash (6*8*2-4=92)
52W;               Print a newline

56W1M4W;           Print a pipe ((5*6+1)*4=124)
![1A84W;]%         Same loop as second
56W1M4W;           Print a pipe
.
\$\endgroup\$
5
\$\begingroup\$

Integral, 37 31 Bytes

♂8♦⌡_⌡g►⌡/⌡•8g►⌡\⌡►•⌡|⌡♦8g►⌡|⌡►

First real answer in my new language!

Try it

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
►      Concatenate
⌡\⌡    Push backslash
•      Stack: ...abc -> ...bca
⌡|⌡    Push pipe
♦      Swap
8      Push space
g      Repeat string
►      Concatenate
⌡|⌡    Push pipe
►      Concatenate
\$\endgroup\$
3
  • 3
    \$\begingroup\$ While answering your own challenges is perfectly acceptable, I recommend giving people a week before you go ahead and do so. This is because, as the challenge author, you've already had plenty of time to think about the problem. \$\endgroup\$
    – Adám
    Commented Aug 3, 2020 at 15:55
  • 1
    \$\begingroup\$ @petStorm I added that. It is now v. \$\endgroup\$
    – nph
    Commented Aug 4, 2020 at 11:58
  • \$\begingroup\$ @Adám how does it stop people from submitting their own answers? Especially in a new language that almost nobody has seen before \$\endgroup\$
    – Dion
    Commented Aug 5, 2020 at 7:45
4
\$\begingroup\$

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è       #  Use the map-index to index into this string
            º      #  Mirror the character (" "→"  "; "/"→"/\"; "|"→"||")
             S     #  Convert the string to a pair of characters
              s    #  Swap so the "_"/" "-string is at the top of the stack
               ý   #  Join the pair with this string as delimiter
                ,  #  And output it with trailing newline
\$\endgroup\$
3
\$\begingroup\$

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
        % produces the matrix [1 0 0; 1 0 0; ...; 1 0 0] with n rows
95*     % Multiply each entry by 95 (ASCII code of '_'). This gives the central
        % columns of the output, but transposed, as an n×3 matrix (**)
' \|'   % Push this string: last column of the output, but as a row (***)
v       % Concatenate (*), (**) and (***) vertically
!       % Transpose. Implicitly display
\$\endgroup\$
3
\$\begingroup\$

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 Jelly)
      “  “/\“||”    - list of lists of characters = [[' ', ' '], ['/', '\'], ['|', '|']]
                 "  - zip together applying:
                j   -   join -> [[' ', '___', ' '], ['/', '   ', '\'], ['|', '   ', '|']]
                  Y - join with newlines -> [' ', '___', ' ', '\n', '/', '   ', '\', '\n', '|', '   ', '|']
                    - implicit, smashing print
                      >>> ___ 
                      >>>/   \
                      >>>|   |
\$\endgroup\$
3
\$\begingroup\$

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!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ @AryanBeezadhur ECMAScript, 8th edition. Also known as ECMAScript 2017, in which padEnd() was first introduced. \$\endgroup\$
    – Arnauld
    Commented Nov 8, 2020 at 16:17
3
\$\begingroup\$

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 previous comamnd
\$\endgroup\$
3
\$\begingroup\$

Japt, 20 bytes

" {ç'_}
/{ç}\\
|{ç}|

Try it

ç is one of Japt's repeat methods for integers; you can probably figure the rest out from there!

\$\endgroup\$
3
\$\begingroup\$

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

\$\endgroup\$
2
  • 1
    \$\begingroup\$ ? 41 bytes \$\endgroup\$
    – mazzy
    Commented Aug 4, 2020 at 20:14
  • 1
    \$\begingroup\$ reductio ad absurdum: 41 bytes \$\endgroup\$
    – mazzy
    Commented Aug 4, 2020 at 20:19
3
\$\begingroup\$

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 of "_"
  +"\n/x\\\n|x|"     //  Appended with "
                     //   /x\
                     //   |x|",
   .replace("x",     //  of which the "x" are replaced with:
     " ".repeat(n))  //   The input amount of spaces
\$\endgroup\$
0
3
\$\begingroup\$

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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Welcome to the site! Your 43 byte solution also works in Python 2, so you should be able to claim this standing bounty for outgolfing @xnor's 47 byte answer. \$\endgroup\$
    – Dingus
    Commented Aug 8, 2020 at 7:01
3
\$\begingroup\$

COW, 420 bytes

MoOMoOMoOMoOMoOMoOMoOMMMMoOMoOMoOmoOMMMMOOMMMMOOmoOMoOmOoMOomooMMMMOomoooommoOMoOMoOMoOMoOMooMMMmoOMMMMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMMMMOOmoOMoOMoOMOOmoOMoOmOoMOomoomOoMOomooMMMmoOmoOMMMmOoMMMMoOmOomOomOoMMMMOOmoOmoOmoOMoomOomOomOoMOomooMMMmOoMoomoOmoOmoOMoomOomOoMMMMOOmoOMoomOoMOomoomoOmoOmoOMOoMOoMOoMoomOomOomOomOoMoomoOMMMmoOMMMMOOmoOmoOMoOmOomOoMOomooMMMmoOmoOMMMMoomOomOomOoMOOmoOMoomOoMOomooMMMMoo

Try it online!

Pretty happy with 140 instructions (3 bytes per instruction) considering that the ASCII values of the six required characters sum to 400.

Commented

MoOMoOMoOMoOMoOMoOMoO # push 7 to 1st memory block 						blocks: [[7]], register: nil
MMM		      # copy to register 							blocks: [[7]], register: 7
MoOMoOMoO	      # add 3 to 1st block 							blocks: [[10]], register: 7
moOMMM		      # paste 7 to 2nd block							blocks: [10, [7]], register: nil
MOOMMMMOOmoOMoOmOoMOomooMMMMOomoo # set 3rd block to 28 = 7 + 6 + 5 + 4 + 3 + 2 + 1		blocks: [10, [0], 28], register: nil
oom		      # read input n (e.g. 3) into 2nd block					blocks: [10, [3], 28], register: nil
moOMoOMoOMoOMoO	      # add 4 to 3rd block							blocks: [10, 3, [32]], register: nil
Moo		      # print ASCII character 32 (space)					blocks: [10, 3, [32]], register: nil
MMMmoOMMM	      # copy and paste 32 to 4th block						blocks: [10, 3, 32, [32]], register: nil
MoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoO # add 15 to 4th block				blocks: [10, 3, 32, [47]], register: nil
MMMMOOmoOMoOMoOMOOmoOMoOmOoMOomoomOoMOomooMMM # add 2 to 6th block 47 times			blocks: [10, 3, 32, [47], 0, 94], register: nil
moOmoOMMMmOoMMM	      # copy and paste 94 to 5th block						blocks: [10, 3, 32, 47, [94], 94], register: nil
MoO		      # add 1 to 5th block							blocks: [10, 3, 32, 47, [95], 94], register: nil
mOomOomOoMMMMOOmoOmoOmoOMoomOomOomOoMOomooMMM # print ASCII character 95 (underscore) n times	blocks: [10, [3], 32, 47, 95, 94], register: nil
mOoMoo		      # print ASCII character 10 (newline)					blocks: [[10], 3, 32, 47, 95, 94], register: nil
moOmoOmoOMoo	      # print ASCII character 47 (forward slash)				blocks: [10, 3, 32, [47], 95, 94], register: nil
mOomOoMMMMOOmoOMoomOoMOomoo # print n spaces							blocks: [10, [0], 32, 47, 95, 94], register: 3
moOmoOmoOMOoMOoMOo    # subtract 3 from 5th block						blocks: [10, 0, 32, 47, [92], 94], register: 3
Moo		      # print ASCII character 92 (backslash)					blocks: [10, 0, 32, 47, [92], 94], register: 3
mOomOomOomOoMoo	      # print newline								blocks: [[10], 0, 32, 47, 92, 94], register: 3
moOMMMmoOMMMMOOmoOmoOMoOmOomOoMOomooMMM # add 32 to 5th block					blocks: [10, 3, [32], 47, 124, 94], register: nil
moOmoOMMM             # copy 124 to register							blocks: [10, 3, 32, 47, [124], 94], register: 124
Moo	              # print ASCII character 124 (pipe)					blocks: [10, 3, 32, 47, [124], 94], register: 124
mOomOomOoMOOmoOMoomOoMOomoo # print n spaces							blocks: [10, [0], 32, 47, 124, 94], register: 124
MMMMoo	              # paste 124 to 2nd block and print as ASCII character			blocks: [10, [124], 32, 47, 124, 94], register: nil
\$\endgroup\$
3
  • 1
    \$\begingroup\$ That is some beefy source code you got there. \$\endgroup\$
    – Razetime
    Commented Aug 8, 2020 at 14:53
  • \$\begingroup\$ Now do Whirl \$\endgroup\$ Commented Oct 16, 2020 at 18:21
  • \$\begingroup\$ This is truly beautiful \$\endgroup\$
    – user98765
    Commented Oct 16, 2020 at 18:58
2
\$\begingroup\$

Ruby, 36 bytes

->n{" #{?_*n}
/#{a=" "*n}\\
|#{a}|"}

Try it online!

\$\endgroup\$
2
\$\begingroup\$

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

\$\endgroup\$
2
\$\begingroup\$

Haskell, 58 bytes

f n|x<-' '<$[1..n]=' ':('_'<$x)++"\n/"++x++"\\\n|"++x++"|"

Try it online!

\$\endgroup\$
2
\$\begingroup\$

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!

\$\endgroup\$
0
2
\$\begingroup\$

Perl 5 -p, 40 bytes

say$"._ x$_,$/,$_='/'.$"x$_.'\\';y/ /|/c

Try it online!

\$\endgroup\$
2
\$\begingroup\$

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 = [" /|", " \|"]
    "_  "           String literal.
  R⁰                Repeat n times: y = ["_  ", "_  ", "_  "]
 J                  Join x by this list: [" /|", "_  ", "_  ", "_  ", " \|"]
                    Since x and y are lists of strings, y is inserted between
                    each pair of elements in x and the result is flattened
                    to keep the types consistent.
T                   Transpose: [" ___ ", "/   \", "|   |"]
                    Implicitly print, separated by newlines.
\$\endgroup\$
2
\$\begingroup\$

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
             Ó /   # Find and replace ...
              Ó    # all Non-whitespace (\S == <M-S>)
                |  # with a '|'

Haven't done one of these in a while.

Try it online!

\$\endgroup\$
2
\$\begingroup\$

MAWP v1.1, 92 bytes

%@_1A84W;[1A~25WWM~]%!![1A92W1M5W;]%67M;85W7M;[1A84W;]%45W3M4W;67M;65W1M4W;[1A84W;]65W1M4W;.

Try it!

\$\endgroup\$
2
\$\begingroup\$

1+, 174 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+"*""1+""*+*+";()/;

Don't ask me how this work, I don't know at all!

I didn't yet try to golf it down (although I probably can offer a 50% discount on the bytecount when I have time), and there's still a lot of repetitions. But at least I made it.

1+ 174 vs 92 MAWP v1.1. Fiasco.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ They called me a madman for my MAWP... :D \$\endgroup\$
    – Dion
    Commented Aug 10, 2020 at 11:06
2
\$\begingroup\$

Pepe, 118 bytes

REeEeEEEEErEeErREEeeeEReREEEEEEeRREeeEeeeeeReeereeEreeeEeEEEEREEEEeeEREEeeeEReeereeEeEEEeereeERrEeEEEEEeerreEeReeereEe

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Ha you are the one who is no longer on Esolangs \$\endgroup\$ Commented Aug 10, 2020 at 13:18
2
\$\begingroup\$

MATLAB/Octave, 36 32 bytes

@(n)[' /|';'_  '+~(1:n)';' \|']'

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 get the desired orientation.

This works as trailing spaces are allowed, so a fully populated matrix can be formed. If trailing spaces were disallowed, the code would be 6 bytes longer by wrapping the result in trim(...).


  • Saved 4 bytes by duplicating the string literal using array expansion rather than with repmat. Thanks @LuisMendo.
\$\endgroup\$
5
  • \$\begingroup\$ @LuisMendo Interesting. Never come across that one. I assume it's Octave specific? \$\endgroup\$ Commented Sep 2, 2020 at 17:12
  • \$\begingroup\$ Matlab has implicit expanstion since Release 2016b. Octave has had that feature (called broadcasting, but it's the same) for longer, at least since version 3.6.0. So the code I suggested works both in Octave and in reasonably modern Matlab \$\endgroup\$
    – Luis Mendo
    Commented Sep 2, 2020 at 17:41
  • \$\begingroup\$ @LuisMendo interesting. A large part of my work ends up benig programming MATLAB stuff, and have somehow missed that feature. Cool to learn new things! \$\endgroup\$ Commented Sep 2, 2020 at 19:18
  • 1
    \$\begingroup\$ Ooooh! I've just realised what it's doing, on first glance it looked like the (1:n) bit was inside the string literal, but just realised its not. Yes that makes more sense now. \$\endgroup\$ Commented Sep 2, 2020 at 19:21
  • \$\begingroup\$ Yes, it's a cool feature, not just for golfing :-) \$\endgroup\$
    – Luis Mendo
    Commented Sep 2, 2020 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.