Skip to main content
Saved 8 more bytes by adjusting how the slicing works
Source Link
AdmBorkBork
  • 43.5k
  • 5
  • 103
  • 284

PowerShell v2+, 99 9090 82 bytes

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

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 " "*($n+$i++$_+$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.

PowerShell v2+, 99 90 bytes

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

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 " "*($n+$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.

PowerShell v2+, 99 90 82 bytes

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

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.

Saved 9 bytes by eliminating $x
Source Link
AdmBorkBork
  • 43.5k
  • 5
  • 103
  • 284

PowerShell v2+, 9999 90 bytes

param($n)1..$n|%{$x="" "*($_*2$n-2)+"\";if($_-ge4){$x="+"/----/"+-join(" "*($_-3+$i++$n+$i++)+"\    \"}" "*)[($n$n+6-$_)+"/----/$x"..($n+5+$i)]}

Takes input $n, starts a loop from 1 to $n with |%{...}. Each iteration, we set a helper variable $x equal towe're constructing a string. We start with the appropriate number of spaces and a \" "*($n-$_). This is calculated out to be the top part of the slide that's partially hidden by and the ladder. However, if we're at (counting from the top down) rung 4"/----/" or greater.

To that, we immediately change our mind and setadd another string that's been sliced $x[...] equal to enough spacesand $_-3+$i++join and thened back together. The second string is the full slide width \ \. Next, we count out how many prepending spacesand we need (based on how tall ourassume that the whole slide is and where we're atalways visible. It's the number of spaces before the slide would start $n-$_" "*($n+$i++)), followed by the ladder "/----/ and our previous variableslide itself $x""\ \". This is sliced by a range calculated out to be the part of the "spaces plus slide" that's partially hidden by the ladder.

PowerShell v2+, 99 bytes

param($n)1..$n|%{$x=" "*($_*2-2)+"\";if($_-ge4){$x=" "*($_-3+$i++)+"\    \"}" "*($n-$_)+"/----/$x"}

Takes input $n, starts a loop from 1 to $n with |%{...}. Each iteration, we set a helper variable $x equal to a number of spaces and a \. This is calculated out to be the top part of the slide that's partially hidden by the ladder. However, if we're at (counting from the top down) rung 4 or greater, we immediately change our mind and set $x equal to enough spaces $_-3+$i++ and then the full slide width \ \. Next, we count out how many prepending spaces we need (based on how tall our slide is and where we're at $n-$_), followed by the ladder "/----/ and our previous variable $x".

PowerShell v2+, 99 90 bytes

param($n)1..$n|%{" "*($n-$_)+"/----/"+-join(" "*($n+$i++)+"\    \")[($n+6-$_)..($n+5+$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 " "*($n+$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.

Source Link
AdmBorkBork
  • 43.5k
  • 5
  • 103
  • 284

PowerShell v2+, 99 bytes

param($n)1..$n|%{$x=" "*($_*2-2)+"\";if($_-ge4){$x=" "*($_-3+$i++)+"\    \"}" "*($n-$_)+"/----/$x"}

Takes input $n, starts a loop from 1 to $n with |%{...}. Each iteration, we set a helper variable $x equal to a number of spaces and a \. This is calculated out to be the top part of the slide that's partially hidden by the ladder. However, if we're at (counting from the top down) rung 4 or greater, we immediately change our mind and set $x equal to enough spaces $_-3+$i++ and then the full slide width \ \. Next, we count out how many prepending spaces we need (based on how tall our slide is and where we're at $n-$_), followed by the ladder "/----/ and our previous variable $x".

Examples

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

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