# Draw a ladder and slide

Your task is to create a program or function that takes, as input, a natural number (n) between 1 and 25 (inclusive) and prints an isometric representation of a slide and ladder with n number of rungs.

The ladder is always oriented on the left and the slide on the right. We're viewing it from the ladder side, so part of the slide is obscured at the top three levels. The rungs are represented by four dashes (----) and the sides of the ladder and slide by slashes (/ and \). The following is a diagram to represent the patterns of spaces needed for a slide with five rungs.

Slide              Blank space count
/----/\        1234/----/\
/----/  \       123/----/12\
/----/    \      12/----/1234\
/----/ \    \     1/----/1\1234\
/----/   \    \    /----/123\1234\


### Examples

>>1
/----/\

>>3
/----/\
/----/  \
/----/    \

>>4
/----/\
/----/  \
/----/    \
/----/ \    \

>>10
/----/\
/----/  \
/----/    \
/----/ \    \
/----/   \    \
/----/     \    \
/----/       \    \
/----/         \    \
/----/           \    \
/----/             \    \


This is code-golf, so the answer with the lowest byte count wins.

Note: trailing white space is acceptable in the output, as long as it doesn't exceed the length of the line.

• You would break your legs at the end of that slide! – Fatalize Jul 20 '16 at 12:06
• @Fatalize that'd be... Fatal. – Ven Jul 20 '16 at 12:07
• @Fatalize bonus points for you if you draw a pool at the bottom ;) – atlasologist Jul 20 '16 at 12:08
• @atlasologist A pool of blood? – Neil Jul 20 '16 at 19:09
• Apologies if this is a dumb question, but a couple of the answers below (Python, JavaScript) define a function that returns a string rather than printing it. Is that kosher? – Jordan Jul 20 '16 at 20:11

## Retina, 8172 52 bytes

Byte count assumes ISO 8859-1 encoding.

.+
$* /\ \ ^. + /(.+)$
$&¶$%/  $1 /.{5} /----/  Try it online! ### Explanation The program consists of four stages, all of which are regex substitutions (with a couple of Retina-specific features). I'll use input 5 as an example for the explanation. Stage 1 .+$* /\    \


This turns the input n into n spaces followed by /\ \ which will become the top of the ladder/slide:

     /\    \


For now, we'll just show the slide in full and represent the ladder only by its left-hand /.

Stage 2

^.



Unfortunately, n spaces are one more than we need, so we remove the first character again. We've now got:

    /\    \


Stage 3

+ /(.+)&¶$%/$1


Time to expand the complete structure. Knowing where the top is, is sufficient to build the entire thing, because we can simply extend it one line at a time, moving the ladder and the slide apart by two spaces.

The + tells Retina to repeat this stage in a loop until the output stops changing (in this case, because the regex stops matching). As for the regex itself, we simply match the / on the last line and everything after it and we also match one space in front of it, which means this can no longer match once / has reached the first column.

Here's what we replace this with:

 $& The match itself. We don't want to remove the line we already have. ¶ A linefeed, because we want to append a new line.$%   This is a very recent addition to Retina: it's like the normal $ but is bounded by linefeeds. That means this inserts everything in front of the match which is on the same line. In particular this one space less than the indentation of the matched line, hence we are shifting the / one column left. / A literal /, representing the left edge of the ladder. > < Two spaces, so that we can shift the slide one column right.$1    Capturing group 1 which contains the slide and its separation from


So at each iteration, this adds one line to the string, until we end up with this:

    /\    \
/  \    \
/    \    \
/      \    \
/        \    \


Stage 4

/.{5}
/----/


All that's left is getting the ladder right. That's really simple, we just match the / and the next 5 characters and insert the correct ladder representation, thereby overriding the slide or spaces that are already there:

    /----/\
/----/  \
/----/    \
/----/ \    \
/----/   \    \


# V, 38, 37, 36, 34, 33, 32, 31, 30 29 bytes

Àé r\2é/4é-òhYpX$2P^ò3GEòjlr\  Try it online! I might catch up with Osabie. One byte shorter than Osabie. \o/ Tied with 2sable! One byte shorter! In other news, this is definitely the longest strikethrough header I've ever made. Explanation: Àé "Insert 'arg1' spaces r\ "Turn the last one into a '\' 2é/ "Insert 2 '/' 4é- "Insert 4 '-' ò ò "Recursivly: h " Move one to the left Yp " Duplicate this line X " Delete one space from the left$2P        "  Paste two spaces at the end of this line
^       "  Move back to the beginning of this line.


This will run until an error occurs, which thanks to the "move left" command ('h'), will be 'arg1' times.

Now we just need to add the inner leg

3GE             "Move to the second slash of line 3
ò    ò       "Recursively: (The second 'ò' is implicit)
jl          "  Move down and to the right
r\        "  And replace the character under the cursor with a '\'


Non-competing version (28 bytes)

## Pyth, 39 35 bytes

VQ++*dt-QN"/----/">+*+ddN"\    \\"5


Explanation:

VQ                                  # Interate over 0 -> Q-1 (Q is the input)
+                                 # Concatenate the 2 halfs of the slide
+                                # Concatenate the whitespace block and the ladder
*d                              # Multiply d (whitespace) by this number \/
t-QN                          # Calculate the amount of spaces before : input - step of the iterarion -1
>               5 # Remove the first 5 chars  from the string generated in the following lines
+                # Concatenate the whitespace block and the slide
*+ddN           # Multiply "+dd" (2 whitespace) by the step of the iterarion to generate the space between the ladder and the slide
"\    \\"  # Slide


Test here

# 2sable, 403632 30 bytes

Hmmm, V is coming awfully close...

F¹N-<ð×…/--Â«ðð«N×…\  Â««5F¦}¶


Uses the CP-1252 encoding. Try a 05AB1E compatible version!.

• And the battle rages on: codegolf.stackexchange.com/a/85985/31716 :P – DJMcMayhem Jul 20 '16 at 18:28
• @DrGreenEggsandIronMan Hmmm!!?!?! – Adnan Jul 20 '16 at 19:22
• There's one more off, and one more once I get home. Also, I'm not switching languages. :P – DJMcMayhem Jul 20 '16 at 19:35

## PowerShell v2+, 9990 82 bytes

param($n)1..$n|%{" "*($n-$_)+"/----/"+-join(" "*($_+$i++)+"\    \")[6..(6+$_+$i)]}


Takes input $n, starts a loop from 1 to $n with |%{...}. Each iteration, we're constructing a string. We start with the appropriate number of spaces " "*($n-$_) and the ladder "/----/".

To that, we add another string that's been sliced [...] and -joined back together. The second string is the slide, and we assume that the whole slide is always visible. It's the number of spaces before the slide would start " "*($_+$i++), followed by the slide itself "\ \". This is sliced by a range calculated out to be the part of the "spaces plus slide" that's partially hidden by the ladder.

### Examples

PS C:\Tools\Scripts\golfing> .\draw-a-ladder-and-slide.ps1 7
/----/\
/----/  \
/----/    \
/----/ \    \
/----/   \    \
/----/     \    \
/----/       \    \

/----/\
/----/  \
/----/    \
/----/ \    \
/----/   \    \
/----/     \    \
/----/       \    \
/----/         \    \
/----/           \    \
/----/             \    \
/----/               \    \
/----/                 \    \
/----/                   \    \
/----/                     \    \
/----/                       \    \

• +1 because the slashes in your directory line up with the slashes in the test output. :D – DJMcMayhem Jul 20 '16 at 19:04
• Your \golfing folder must be very organized ._. – Conor O'Brien Jul 20 '16 at 19:15

# Python 2 - 7976 75 bytes

x=input()
for i in range(x):print(x-i)*' '+'/----/'+(i*'  '+'\\    \\')[5:]


Thanks to Hubert Grzeskowiak for "disqualifying" me since making my program print actually saved 3 bytes! Thanks also to Eʀɪᴋ ᴛʜᴇ Gᴏʟғᴇʀ for saving 1 more byte!

• Nice! By the way, lambda was okay, I think, since strictly speaking it is a sort of function. Using lambda you can save a newline and a space :-) – Hubert Grzeskowiak Jul 20 '16 at 21:45
• Wait, I actually tried it with lambda and couldn't get it working. It's bc of the print, I guess? – Hubert Grzeskowiak Jul 20 '16 at 22:08
• @HubertGrzeskowiak Well it depends on challenge specifications. If the question asked for a program/function that returns a string representation of a slide, either of my answers would be valid. Since it specifies "print" as you pointed out, I would have either needed to name the lambda function and print a call to it, or do what I did above which was shorter. – Cowabunghole Jul 20 '16 at 22:29
• The specs don't tell that the function has to be named, or be called ;-) – Hubert Grzeskowiak Jul 20 '16 at 23:35
• Convert it to a full program: replace def f(x): with x=input(), and remove the indentation on the second line. This saves you 1 byte. – Erik the Outgolfer Jul 21 '16 at 11:52

# Vim, 71 keystrokes

This is such a stupid way of doing it, but it's a bit of fun. Input is given as a text file with a single line containing an integer. This is likely quite golfable, but it'll do for now (edit: switched style of control characters upon request):

A@qyyPgg<c-v><c-v>GkI <c-v><esc>G$i <c-v><esc><esc> Tq"qDI/----/\^[lD@"ddh<c-v>god:%s/ \\/\\ \\<cr>  <c-v>, <esc> and <cr> are all individual keystrokes; ctrl+v, escape, and carriage return (enter) respectively. For a simple to digest version with the correct literals, here is the file ladder.keys run though xxd: 00000000: 4140 7179 7950 6767 1616 476b 4920 161b A@qyyPgg..GkI .. 00000010: 4724 6920 2016 1b1b 5471 2271 4449 2f2d G$i  ...Tq"qDI/-
00000020: 2d2d 2d2f 5c1b 6c44 4022 6464 6816 676f  ---/\.lD@"ddh.go
00000030: 643a 2573 2f20 2020 2020 5c5c 2f5c 5c20  d:%s/     \\/\\
00000040: 2020 205c 5c0d 0d0a                         \\...


To try it out (assuming a nix with the appropriate tools) take the above, run it through xxd -r and put in the file ladder.keys. Create a file ladder.txt with an integer in it. Then do:

vim -s ladder.keys -u NONE ladder.txt

• We usually write ^V as <c-v> here. – Leaky Nun Jul 21 '16 at 19:23
• @Jordan They are one keystroke each, counting modified keys (shift, ctrl or alt with another key) as one keystroke. The keystrokes are Ctrl+v, escape and enter. – algmyr Jul 21 '16 at 23:28

# bash, 61

for((;i<$1;)){ printf "%$[$1+i]s\ \^M%$[$1-++i]s/----/\n";}  where ^M is a literal carriage return $ ./ladder 1
/----/\
$./ladder 4 /----/\ /----/ \ /----/ \ /----/ \ \$ ./ladder 10
/----/\
/----/  \
/----/    \
/----/ \    \
/----/   \    \
/----/     \    \
/----/       \    \
/----/         \    \
/----/           \    \
/----/             \    \

• I think you should have a single space between / and \ in the 4th row, and 1 less space between slide edges. – Leibrug Jul 21 '16 at 11:25
• It should be 4 dashes, not 5. – algmyr Jul 28 '16 at 13:26
• @algmyr thank you that saves 2 bytes – izabera Jul 28 '16 at 15:09

## JavaScript (ES6), 79 bytes

f=
n=>" ".repeat(n).replace(/./g,"$'/$$\\ \\\n").replace(/\/...../g,"/----/") ; <input type=number min=0 oninput=o.textContent=f(this.value)><pre id=o> Works by taking a string of n spaces, then doing some exotic substitution to get the slide with a support, then replacing the support with a ladder. # Ruby, 61 bytes ->n{n.times{|i|puts"%*s\\ \\\r%*s----/"% [n+i,"",n-i,?/]}}  ### Ungolfed ->(num_rows) { num_rows.times {|row_idx| puts "%*s\\ \\\r%*s----/" % [ num_rows + row_idx, "", num_rows - row_idx, "/" ] } }  I could save two bytes by using '%*s\ \^M%*s----/' (where ^M is a literal carriage return) for the format string, but then Ruby prints the warning "warning: encountered \r in middle of line, treated as a mere space". ¯\_(ツ)_/¯ ### Previous solution (64 bytes) ->n{n.times{|i|puts" "*(n+i)+"\\ \\\r"+" "*(n-i-1)+"/----/"}}  ## Batch, 194 bytes @echo off for /l %%i in (1,1,%1)do call:l %1 %%i exit/b :l set s=\ \ for /l %%j in (1,1,%2)do call set s= %%s%% set s=/----/%s:~7% for /l %%j in (%2,1,%1)do call set s= %%s%% echo%s%  Turned out to be reasonably straightforward: indent the slide, remove the first 7 characters, indent the ladder, remove the leading space. This last bit does involve a little trickery though! # Java, 116 bytes c->{for(int i=0;i<c;i++)System.out.format("%"+(5+c-i)+"s%"+(i<3?i*2+1:2*(i-2))+"s%5s\n","/----/","\\",i<3?"":"\\");};  Unfortunately, you can't [easily] duplicate strings in Java, so I end up abusing the format function. Scala, 95 bytes def l(n:Int)=for(i<- 0 to n-1){println(" "*(n-i-1)+"/----/"+(" "*i+"\\ \\").substring(5))}  ## Haskell, 81 bytes a n=[1..n]>>" " f n=[1..n]>>=(\i->a(n-i)++"/----/"++drop 7(a(2*i)++"\\ \\\n"))  • do i<-[1..n];a(n-i)++"/----/"++drop 7(a(2*i)++"\\ \\\n") saves two bytes. – Lynn Jul 21 '16 at 22:52 # eacal, noncompeting, 386 bytes init . define @ curry push . define ~ curry exec .--func alias$ strap
alias ' string
set n set m cast number arg number 0
set s empty string
label l
@ get n
set n ~ dec
@ space
@ get n
$~ repeat$ ' /----/
@ space
@ get m
@ get n
@ ~ sub
@ ~ dec
@ number 2
@ ~ mul
$~ repeat$ ' \
$newline @ get n @ number 0 if ~ more goto l @$
@ regex gm '   ( {4})(?=.\$)
@ '  $1 print ~ replace  I have officially made the most verbose language possible. I made the comment in jest and in sarcasm. Please calm down. Instructions on how to run in the github repo linked in the header. ## Ungolfed init . set n set m cast number arg number 0 set s empty string label loop push . get n set n exec .--func dec push . space push . get n strap exec .--func repeat strap string /----/ push . space push . get m push . get n push . exec .--func sub push . exec .--func dec push . number 2 push . exec .--func mul strap exec .--func repeat strap string \ strap newline push . get n push . number 0 if exec .--func more goto loop push . strap push . regex gm string ( {4})(?=.) push . string$1
print exec .--func replace

• "I have officially made the most verbose language possible." Excuse me, have you heard of AppleScript? – Addison Crump Jul 20 '16 at 23:53
• @VTCAKAVSMoACE Alright, let's make a deal. You answer this question in applescript. Then I'll tell you this is more verbose. – Conor O'Brien Jul 21 '16 at 1:53
• It's not verbose enough if you can ungolf it. – Neil Jul 21 '16 at 8:30
• @VTC, TimmyD, and Neil: Geez. You happy now? – Conor O'Brien Jul 21 '16 at 19:31
• @CᴏɴᴏʀO'Bʀɪᴇɴ We're obviously joking around, lol – Addison Crump Jul 21 '16 at 21:36