22
\$\begingroup\$

Task

Given a positive integer n, draw the corresponding rocket.

Examples

From n = 1 to 4 the rockets are below. For your program's output, the trailing newline after a rocket is optional.

  |
 / \
*---*
| o |
| o |
*---*
 /_\

   |
  / \
 /   \
*-----*
| o o |
| o o |
| o o |
| o o |
*-----*
 /___\

    |
   / \
  /   \
 /     \
*-------*
| o o o |
| o o o |
| o o o |
| o o o |
| o o o |
| o o o |
*-------*
 /_____\

     |
    / \
   /   \
  /     \
 /       \
*---------*
| o o o o |
| o o o o |
| o o o o |
| o o o o |
| o o o o |
| o o o o |
| o o o o |
| o o o o |
*---------*
 /_______\

You can check this reference implementation (ungolfed).


This is so shortest submission in bytes, wins! If you liked this challenge, consider upvoting it... And happy golfing!

\$\endgroup\$
  • 1
    \$\begingroup\$ @Arnauld nope, he wish! This fabulous design is mine. The final product of countless hours spent refactoring the whole thing, redrawing bits time after time... Finding the fine balance between elegance and efficiency... \$\endgroup\$ – RGS Feb 20 at 12:38
  • 1
    \$\begingroup\$ @ShaunBebbers what does that mean? \$\endgroup\$ – RGS Feb 20 at 14:00
  • 1
    \$\begingroup\$ @RGS = Is an alternative codepage encoding acceptable as output? \$\endgroup\$ – petStorm Feb 20 at 14:01
  • 1
    \$\begingroup\$ @ShaunBebbers I don't mind the codepoints being different. If you want to use something weird (weird is good!) that doesn't support ascii and you can still make a rocket similar to the one shown, go for it! I don't mind \$\endgroup\$ – RGS Feb 20 at 15:24
  • 2
    \$\begingroup\$ This is the very first non-trivial programming task I ever accomplished; I think I was seven. I did not own a computer; I worked out the program to draw the rockets on paper and then typed it in to the Commodore PET in the school library after school. What a charming question! \$\endgroup\$ – Eric Lippert Feb 22 at 5:20

16 Answers 16

14
\$\begingroup\$

PowerShell, 131 117 bytes

param($n)' '*$n+" |"
$n..1|%{" "*$_+"/$(' '*++$i)\";$x="*-$('-'*++$i)*"}
$x
,("| $('o '*$n)|")*$i
$x
" /$('_'*--$i)\"

Try it online!

Line breaks added for clarity, but they could just as easily be ; (it's the same byte count either way).

We're basically brute-force building the rocket one line at a time. We start by taking input $n, then construct a string of $n spaces and the nose antenna. We then loop from $n down to 1, using a triangular number trick with $i to get the appropriate number of middle spaces for the nose cone. Including the construction of the joiner into the loop allows us to re-use ++$i to both create the joiner and increment for our triangular number, saved into $x for later use.

We then use array-multiplication with the comma operator to construct the body of the rocket, then $x onto the pipeline again for the bottom. Finally we output the engine part with the appropriate _ in between.

All of those strings are left on the pipeline, and default implicit output gives us newlines for free.

-14 bytes thanks to VisualMelon.

|improve this answer|||||
\$\endgroup\$
  • 1
    \$\begingroup\$ Dammit, I was working on this approximately this exact answer. \$\endgroup\$ – Veskah Feb 20 at 14:35
  • \$\begingroup\$ Quite cool! +1 for this one :D \$\endgroup\$ – RGS Feb 20 at 15:28
  • \$\begingroup\$ You can trade the quoted addition for raw text: ' '*($n+1)+"|" -> ' '*$n+" |"? Also, I think you can shave quite a handful of bytes by switching to inlined expressions in some of the strings, e.g. ($x=''+'-'*++$i+'')` -> ($x="*$('-'*++$i)*") ($(stuff) is cheaper than the "+stuff+"). Inlining the extra '-' there also means you can use $i instead of 2*$n, and --$i instead of ($i-2) later on. You can also assign $x in the loop to save 2 bytes. \$\endgroup\$ – VisualMelon Feb 21 at 9:58
  • \$\begingroup\$ Adding 3 bytes so that $i is initialised (param($n,$i)) I get 120 bytes: tio.run/… \$\endgroup\$ – VisualMelon Feb 21 at 9:58
  • \$\begingroup\$ @VisualMelon $i is perfectly happy being created and set with ++$i See here with it removed \$\endgroup\$ – Veskah Feb 21 at 13:16
8
\$\begingroup\$

Charcoal, 38 bytes

NθP×θ_←↗¹Pθ←²↑*↑⊗θ↘*UO⊕θ⊗θo ↑P⊕θ↑↗θ|‖B

Try it online! Link is to verbose version of code. Works by drawing the left half of the rocket and reflecting it. Explanation:

Nθ

Input the size of the rocket.

P×θ_

Print the _s at the base of the rocket.

←↗¹

Move left and print the / at the left of the base.

Pθ←²

Print the -s on the second layer.

↑*↑⊗θ↘*

Print the left side of the rocket, and leave the cursor inside the body.

UO⊕θ⊗θo ↑

Fill the rocket with os and move the cursor up.

P⊕θ↑

Print the top row of -s and move the cursor up.

↗θ|‖B

Print the nose cone and reflect to complete the rocket.

Alternate solution, also 38 bytes:

Nθ×θ_↖¹P←θ²↑*F⊗θ←⪫|¶… o⊕θP←⁺²θ↖*↖θ|‖B←

Try it online! Link is to verbose version of code. Works by drawing the right half of the rocket and reflecting it. Explanation:

Nθ

Input the size of the rocket.

×θ_↖¹

Print the base of the rocket.

P←θ²↑*

Print the second layer.

F⊗θ←⪫|¶… o

Print the body of the rocket.

⊕θP←⁺²θ↖*

Print the top of the rocket.

↖θ|‖B←

Print the nose cone and reflect to complete the rocket.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ +1 charcoal answers to ASCII art challenges are really nice! \$\endgroup\$ – RGS Feb 20 at 11:37
  • \$\begingroup\$ The fact that this sequence can even be described uniquely in 38 bytes is mind boggling \$\endgroup\$ – Cruncher Feb 20 at 21:25
  • 1
    \$\begingroup\$ @Cruncher uniquely? But I did it in two different ways... \$\endgroup\$ – Neil Feb 21 at 0:08
  • \$\begingroup\$ And they both uniquely describe the sequence lol. As in, unambiguously. Anything that's a solution to this problem uniquely describes the sequence \$\endgroup\$ – Cruncher Feb 21 at 0:36
8
\$\begingroup\$

Python 2, 165 154 bytes

i=input()
m=["*-"+"--"*i+"*"]
print"\n".join([" "*i+" |"]+[" "*(i-x)+"/ "+"  "*x+"\\"for x in range(i)]+m+["|"+" o"*i+" |"]*2*i+m+[" /"+"_"*(i*2-1)+"\\"])

Try it online!

-11 with thanks to @wilkben for some great hints

Nothing very exciting here. Just builds each line in a list and then prints with '\n'.join().

|improve this answer|||||
\$\endgroup\$
7
\$\begingroup\$

T-SQL, 265 bytes

DECLARE @n INT=0,@o varchar(max)=''z:SELECT
@o+=space(@-@n)+'/'+replicate(' ',@n*2)+' \ 
',@n+=1IF @n<@ GOTO z
PRINT space(@)+' |
'+@o+stuff(replicate('*'+replicate('-',@*2+1)+'*
',2),5+2*@,0,replicate('|'+replicate(' o',@)+' |
',2*@))+' /'+replicate('_',@*2-1)+'\'

Try it online

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Yet another surprising SQL submission! Thanks for your work +1 \$\endgroup\$ – RGS Feb 20 at 13:46
4
\$\begingroup\$

IBM/Lotus Notes Formula Language, 262 246 236 bytes

L:=@NewLine;M:="*"+@Repeat("-";i*2+1)+"*"+L;N:=@Repeat(" ";i+1)+"|"+L;
@For(x:=0;x<i;x:=x+1;@Set("N";N+@Repeat(" ";i-x)+"/"+@Repeat(" ";x*2+1)+"\\"+L));
@Set("N";N+M+@Repeat("|"+@Repeat(" o";i)+" |"+L;2*i)+M+" /"+@Repeat("_";i*2-1)+"\\");

Basically a port of my Python 2 answer. Newlines in the code added for readability. They are not required by the interpreter. The formula takes it's input from i which is a numeric field on the same form.

There is no online interpreter for Notes formula so here is a screen shot of the output from 1 to 4:

enter image description here

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ This looks nice :) good job! +1 \$\endgroup\$ – RGS Feb 20 at 15:38
  • 1
    \$\begingroup\$ Thanks. Haven't done an ASCII art challenge for a while. They are usually quite fun to port to Formula mainly to see if I can still remember how to use it :) \$\endgroup\$ – ElPedro Feb 20 at 17:29
  • \$\begingroup\$ What's 0? I've tested almost all of these and some are pretty funny. \$\endgroup\$ – S.S. Anne Feb 21 at 0:39
  • 1
    \$\begingroup\$ @S.S.Anne 0 is basically a pile of rubble which is what you would expect as 0 is not a positive integer. How the output renders depends on the font. The above is using Default Monospace. You can have hours of harmless fun trying it with different fonts :) \$\endgroup\$ – ElPedro Feb 21 at 8:10
  • \$\begingroup\$ Yeah, but the rubble is different for every answer. Mine is like Python's but it has an extra | | in the base. \$\endgroup\$ – S.S. Anne Feb 21 at 11:59
3
\$\begingroup\$

05AB1E, 52 50 47 45 43 bytes

'|'/ILúí`©„ oI>∍'|ìI·иI>'-×'*ì.ø`®ð'_:».º.c

-2 bytes thanks to @Grimmy.

Try it online or verify some more test cases.

Explanation:

'|           '# Push a "|"
  IL          # Push a list in the range [1,input]
'/  ú        '# Push a "/" with that many leading spaces
     í        # And reverse each string so the spaces become trailing
      `       # And push all strings in this list to the stack
       ©      # Store the last one in variable `®` (without popping)
„ o           # Push string "o "
   I>         # Push the input+1
     ∍        # Extend the string to that size
      '|ì    '# And prepend a "|"
         I·   # Push the input doubled
           и  # And repeat the string that many times as list
I>            # Push the input+1 again
  '-×        '# And create a string with that many "-"
     '*ì     '# And prepend a "*"
        .ø    # Then surround the earlier created list with this string
          `   # And push all separated to the stack
®             # Push the string from variable `®` again
 ð'_:        '# And replace all its spaces with "_"
»             # Now join every string on the stack by newlines
 .º           # Mirror it intersected horizontally
   .c         # And centralize each line (which adds leading spaces where necessary)
              # (after which the result is output implicitly)
|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ +1 thanks for your submission! 05AB1E usually does well in ascii art, right? Also, completely off-topic but I'm in The Netherlands for a (very little...) holiday :) \$\endgroup\$ – RGS Feb 20 at 11:40
  • 2
    \$\begingroup\$ @RGS Overall it does pretty good indeed, due to its mirror, centralize, and Canvas buitlins. I have the feeling this can be shorter, though.. And where in The Netherlands will you visit? Enjoy your holiday. :) \$\endgroup\$ – Kevin Cruijssen Feb 20 at 12:49
  • 1
    \$\begingroup\$ @a'_' I highly doubt it, since I live in a village with just 900 residence outside of the tourist parts of The Netherlands. We do have a Bed & Breakfast near where I live though, so who knows. xD \$\endgroup\$ – Kevin Cruijssen Feb 20 at 14:28
  • 1
    \$\begingroup\$ 'oI>и'|šðý2äн => „ oÞI>£'|šJ for -2. \$\endgroup\$ – Grimmy Feb 20 at 16:12
  • 1
    \$\begingroup\$ @Grimmy Thanks. And 2 more by changing it to „ oI>∍'|ì :) \$\endgroup\$ – Kevin Cruijssen Feb 20 at 16:23
3
\$\begingroup\$

Ruby, 130 bytes

->n{["%#{n+2}s"%?|,*(1..n).map{|x|"%#{n-x+2}s%#{x*2}s"%[?/,?\\]},k="*-"+"--"*n+?*,[[?|,*[?o]*n,?|]*" "]*n*2,k," /#{?_*n+=n-1}\\"]}

Try it online!

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Thanks for your Ruby submission! +1 \$\endgroup\$ – RGS Feb 21 at 8:47
3
\$\begingroup\$

Batch, 700 614 573 538 bytes

Program builds the Nth rocket on a line by line basis, incrementing the values used to repeat characters using the N value

Another 41 bytes shaved off by ditching the subroutine and removing all the parentheses fom the For loops that I could.

Input now only accepted as an unquoted parameter (%1 in %F%%%A in (2,1,%1%D%!$!/A W+=1,O+=1,H+=2,_+=2,L+=2) when starting / calling the Batch file.

If the file is started / called without a parameter, it will output rocket n 1 by default.

I think I've hit the end of the line so far as golfing this script goes - I could save 4 bytes by declining to redirect the output of Pause to nul, however doing so would look unseemly. Alternately I could save 2 bytes by outputing to a file in the working directory, but it overcomplicates the use of the program (possible permissions errors).

Found a means to shave another 35 bytes off, by utilising {LF} (Shift + CTRL + J) to terminate lines as opposed to {CR}{LF} (Enter). Unfortunately {LF} characters are not preserved in copy / pasting of code, So:

enter image description here

original 2430 byte script prior to golfing

Pastebin 959 834 725 byte version with Ansi color codes - doesn't takes input

example ANSI colored version output

1893 806 727 byte variant that makes 1 - n rockets.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Hey there! Thanks for your submission! I'm assuming there is no TIO link you can provide? \$\endgroup\$ – RGS Feb 21 at 15:37
  • 1
    \$\begingroup\$ I did take a look over on the TIO website, however batch is not a supported language - I also tied searching cmd, dos, and msdos as possible alternate language names with no luck. \$\endgroup\$ – T3RR0R Feb 21 at 15:44
  • \$\begingroup\$ Does your code take input, though? I'm not sure I understand what is going on, so I don't know if your code works for any n or just the first few ones. \$\endgroup\$ – RGS Feb 21 at 15:46
  • 1
    \$\begingroup\$ works for any n \$\endgroup\$ – T3RR0R Feb 24 at 6:25
3
\$\begingroup\$

C (gcc), 248 bytes

i;f(n){char d[i=2*n+4],o[i];d[i]=o[--i]=!memset(d,45,i);o[--i]=*o='|';*d=d[i]=42;for(i=1+n;i;)printf(--i-n?"%*s/%2$*s\\\n":"%*s|\n",i,"",~i-2*~n-i);for(puts(d);i<=4*n;)i++<=2*n?o[i]="o "[i&1]:puts(o);printf("%s\n /%.*s\\",d,--n,memset(o,95,n+=n));}

This is surprisingly hard to get right, especially with off-by-one errors. I still might be overflowing the stack...

I fixed the bug I mentioned with n=23 and onwards; turns out that i was being decremented in the wrong place, so o was being overwritten and one byte of it was left uninitialized. Luckily, fixing this didn't cost me anything.

I've added a testcase for n=50 and a fun one for n=0.

-11 bytes thanks to ceilingcat!

Try it online!

Also, here's your rocket at n=0:

 |
*-*
*-*
 /| |\

Looks more like space junk to me... Ungolfed and an explanation (plus this weird corner case):

int i;
void f(int n)
{
    char d[i=2*n+4], // holds the *---* line; 2*n+1 dashes plus an extra 3 for the asterisks and the null byte
         o[i];       // holds the | o | line; 2*n+1 for the 'o ' and extra 3 for pipes and null byte

    d[i]=o[--i]=!memset(d,45,i); // null-terminate d and o; set d to dashes starting at d + 1 and ending at d+i-2


    o[--i]=*o='|'; // set the first and last bytes of o to the pipe
    *d=d[i]=42; // set the first and last bytes of d to asterisks

    for(i=1+n;i;) // print top of rocket
        printf(--i-n?"%*s/%2$*s\\\n":"%*s|\n",i,"",~i-2*~n-i); // on first iteration, print the tip and the correct number of spaces; the * before s pads the empty string with a variable number of spaces
// after that, print the cone; use 2$*s to use the second argument to save a byte

// if anyone can figure out how to remove the need for newlines, that would be appreciated

        // print the dashed line
    for(puts(d);i<=4*n;) // generate and print the tube
        i++<=2*n? // first half of loop
          o[i]="o "[i&1] // generate ' o '
          :puts(o); // print the line
    // n+=n here doubles n for the correct number of underscores
    printf("%s\n /%.*s\\",d,--n,memset(o,95,n+=n)); // print the last dashed line and then generate the underscores and print in one go
    // it's shorter doing a sized print than null-terminating o
}

And for the explanation of the corner case: the leading and terminating | are set as well as one character (the ) but never printed because there is only one iteration (as 0 <= 0 and 0 <= 2 * 0). Because n is 0, d is not set by memset, and is printed as | |. The rest should be pretty self-explanatory; the middle is not printed because the loop terminates before it can begin and neither is the cone for pretty much the same reason. There's only one - in *-* because n is 0 (in 2n+1).

|improve this answer|||||
\$\endgroup\$
2
\$\begingroup\$

Wren, 156 bytes

I am very surprised that Arnauld is so easy to outgolf ...

Fn.new{|n|" "*(n+1)+"|
"+(n..1).map{|i|" "*i+"/%(" "*(1+2*(n-i)))\\
"}.join()+"*%("-"*(1+2*n))*
"+"| %("o "*n)|
"*2*n+"*%("-"*(1+2*n))*
 /%("_"*(2*n-1))\\"}

Try it online!

|improve this answer|||||
\$\endgroup\$
  • 3
    \$\begingroup\$ I think the real challenge is outgolfing Arnauld in JS :) +1 for your submission \$\endgroup\$ – RGS Feb 20 at 13:46
2
\$\begingroup\$

JavaScript (ES6),  158  156 bytes

This implements the straightforward repeat everything approach.

n=>` `[N=n*2,R='repeat'](n+1)+`|
${(g=k=>k?` `[R](k)+`/${' '[R](N-k---k)}\\
`+g(k):s=`*${'-'[R](N+1)}*
`)(n)+`|${' o'[R](n)} |
`[R](N)+s} /${'_'[R](N-1)}\\`

Try it online!


JavaScript (ES6),  164  162 bytes

This one builds the rocket recursively.

f=(n,x=y=0,w=2*++n)=>y<w+n?`/\\ |*-o
`[(x>w?x=~!++y:(y?y-n&&~y+3*n?y>n?x&1?2:x%w?6:3:x+y-n&&x-y-n&&2:x%w?5:4:x-n?2:3)||x>n)&7]+f(n,x+1,w):` /${'_'.repeat(w-3)}\\`

Try it online!

Commented

f = (                            // f is a recursive function taking:
  n,                             //   n = size of the rocket
  x = y = 0,                     //   (x, y) = current coordinates
  w = 2 * ++n                    //   w = width of the rocket - 1; increment n
) =>                             //
  y < w + n ?                    // if this is not the last row:
    `/\\ |*-o\n`[                //   pick the next character from this string
      ( x > w ?                  //     if this is the end of the row:
          x = ~!++y              //       increment y and set x to -1
        :                        //     else:
          ( y ?                  //       if this is not the first row:
              y - n &&           //         if this is neither the top
              ~y + 3 * n ?       //         nor the bottom of the tank:
                y > n ?          //           if this is not the fairing:
                  x & 1 ?        //             if x is odd:
                    2            //               append a space
                  :              //             else:
                    x % w ? 6    //               append either a 'o'
                          : 3    //               or a '|' on the borders
                :                //           else (fairing):
                  x + y - n &&   //             append a '/' if we're located on
                  x - y - n && 2 //             a border, or a space otherwise
              :                  //         else (top or bottom of the tank):
                x % w ? 5        //           append either a '-'
                      : 4        //           or a '*' on the borders
            :                    //       else (first row):
              x - n ? 2          //         append either a space
                    : 3          //         or a '|' in the middle
          )                      //
          || x > n               //       turn '/' into '\' if we're in the right side
      ) & 7                      //     turn -1 into 7, false into 0, true into 1
    ] + f(n, x + 1, w)           //   end of character lookup; recursive call with x+1
  :                              // else:
    ` /${'_'.repeat(w - 3)}\\`   //   append the nozzle and stop the recursion
|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Thanks for your submission! What do you mean by "recursively"? Your function f, that I see is being called at the end of the code, is it building different parts of the rocket, depending on its second argument? \$\endgroup\$ – RGS Feb 20 at 12:35
  • \$\begingroup\$ @RGS Each call to f draws exactly one character, except the last call that draws the whole last row at once. \$\endgroup\$ – Arnauld Feb 20 at 12:38
  • \$\begingroup\$ ah ok, I understand now! Thanks \$\endgroup\$ – RGS Feb 20 at 12:46
2
\$\begingroup\$

Python 2, 126 bytes

p=n=input()
s="_ |"+"  \/"*n+"--**"+" o||"*2*n+"--**__\/"
while s:p+=s>"^";print' '*p+s[3]+s[:2]*(n-p)+s[:4:2];s=s[4:];p-=p>0

Try it online!

Includes some trailing whitespace, which I hope is allowed. One of them is the first character of s, a DEL character.

The main idea is to store the design of each line of the rocket in a big template string s. It's a bit easier to see in this slightly less golfed version, where the template for each line is given in a list:

134 bytes

n=input()
p=n+2
w="*--*"
for a,b,c,d in["|   "]+["/  \\"]*n+[w]+["| o|"]*2*n+[w,"/__\\"]:p-=p>0;p+=c=="_";print' '*p+a+(b+c)*(n-p)+b+d

Try it online!

Each line of the rocket is drawn from a template like this with four characters a,b,c,d specified for each line:

  abcbcbcbcbd

It's an a followed by alternating b's and c's followed by a d. The number of leading spaces, which also governs the number of repetitions of bc, is given by p, and is updated with each new line.

I'm aware that Python 3's f-strings and walrus operator could probably shorten many things, but I like Python 2 for golfing ASCII art because it means finding hacks to do things like that instead.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ It looks like a nice submission +1! I'll try to make it a bit shorter :) \$\endgroup\$ – RGS Feb 22 at 11:40
1
\$\begingroup\$

Perl 5, 150 +1 (-p) = 151 bytes

$x=($n=$_)*2;map{$r.=$"x($n-$_).'/'.$"x(2*$_+1).'\
'}0..$n-1;$s='*'.'-'x$x."-*
";$l='|'.' o'x$n." |
";$_=$"x$n.$"."|
$r$s".$l x$x."$s /".'_'x--$x.'\
'

Run with -p, provide input to stdin. Started with basically the reference implementation, and just golfed it down, though there might be better ways. I could save a byte by leaving off the final newline, but I like it better with it in.

Try it online!

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Thanks for your Perl submission! +1 I also like the trailing newline \$\endgroup\$ – RGS Feb 21 at 8:47
1
\$\begingroup\$

C# (Visual C# Interactive Compiler), 292 289 257 bytes

Thanks to @mypronounismonicareinstate -32B

n=>{dynamic r="",t="*",i=n,j;for(;i-->0;)r+=" ";r+=" |\n";for(;++i<n;){for(j=0;j<n+i+2;++j)r+=n-i-j==0?"/":" ";r+=@"\
";}for(;i-->0;)t+="--";t+="-*\n";r+=t;for(;++i<n*2;){r+="|";for(j=0;j++<n;)r+=" o";r+=" |\n";};r+=t+" /";for(;i-->1;)r+="_";return r+"\\";}

Try it online!

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Thanks for your submission! +1 for your work :D \$\endgroup\$ – RGS Feb 20 at 15:29
  • 1
    \$\begingroup\$ 271, a bunch of golfs \$\endgroup\$ – my pronoun is monicareinstate Feb 21 at 1:16
  • \$\begingroup\$ @mypronounismonicareinstate I like your solution. It took me while to understand the the part while(i-->1) I was trying to find what operator is this --> :D Then I found that it is like while(--i>0) \$\endgroup\$ – Jirka Picek Feb 21 at 10:16
  • 1
    \$\begingroup\$ @JirkaPicek Ugh... What is the "-->" operator in C++? (spoiler alert: it's i-- > 1) \$\endgroup\$ – S.S. Anne Feb 21 at 12:23
1
\$\begingroup\$

GolfScript, 95 bytes

v1.0.2, my goal is to get this sub-60, which I think is actually doable.

:i)" ":s*"|"n i,{:j i\-s*"/ "2s*j*"l"n}%"*-""--"i*"*"n+++:q{"| ""o "i*"|"n}2i**q" /""__"i*);"l"

This program uses miniscule L instead of backslash since I spent like four hours today trying to find a way for GS to print ONE backslash and couldn't get it to work. It's ridiculous. Temporary patchfix, looks acceptable in TIO.

WANNA SEE A GROSS PROGRAM?

Okay, so this is obviously a disaster, so we're going to need to go through it very carefully to see why it works. Let's break this into chunks.

:i)" ":s*"|"n                 #Top Needle
i,{:j i\-s*"/ "2s*j*"l"n}%    #Roof
"*-""--"i*"*"n+++:q           #First star-dash line
{"| ""o "i*"|"n}2i**          #Cabin
q                             #Second star-dash line
" /""__"i*);"l"               #Rocket cone

So, that's mildly more digestible for my format. Work is slow today, so enjoy this overly arduous explanation.

Before we start this, I'm clarifying one thing. Input is from the header, slotted right into the stack, and our output is let on the stack, printed out when the program finishes.

:i)" ":s*"|"n     #Print the top needle
:i                #Set our input to i; we'll call it INDEX.
  )               #Increment the INDEX on the stack by 1 (not the variable)
   " ":s          #Put a space on the stack, and make s remember it. We'll call it SPACE.
        *         #Multiply this space by INPUT+1
         "|"      #Needle!
            n     #Newline

So, our stack now looks something like " ""|""/n", which is concatenated all together on output. Every future chunk ends with n characters, and we never back up further in the stack, so we never touch this again.

i,{:j i\-s*"/ "2s*j*"l"n}%    #Print the roof
i,                            #Make an array of size INDEX, from 0 to i-1
  {                     }%    #Block notation. On every element in this array, perform this
  {:j                   }%    #Remember our index as J
  {   i\-               }%    #Subtract J from INDEX
  {      s*             }%    #Make that many spaces
  {        "/ "         }%    #Make a slash then a space
  {            2s*j*    }%    #Make 2*j spaces
  {                 "l" }%    #lmao backslash no work
  {                    n}%    #Add a newline

Which is for what we're looking, for every line. Done INDEX times, we have our roof!. Next!

"*-""--"i*"*"n+++:q   #Print the star-line.
"*-"                  #First two characters.
    "--"              #Next two.
        i*            #We want a number of those double-dashes equal to INDEX.
          "*"         #Last asterisk
             n        #Newline
              +++     #Concatenate that all together. We haven't done this before, but...
                 :q   #We're remembering this entire line in Q, which saves us a TON

Next we have the o-cabin. Surprisingly the easiest part of the program.

{"| ""o "i*"|"n}2i**   #Build the cabin
                2i*    #Double INDEX
{              }   *   #Perform the block 2*INDEX times
{"| "          }   *   #First two characters
{    "o "      }   *   #You know the drill. Combination of the two prev tactics.
{        i*    }   *   #Make that many windows this row
{          "|" }   *   #East wall
{             n}   *   #Newline, as always.

Now comes the trickiest part of the entire program

q      #Print the second star line
q      #Print Q, as established above

And the bottom of the rocket.

" /""__"i*);"l"     #Bottom of the rocket
" /"                #So, how's your day been? Mine's been pretty slow.
    "__"            #Slow enough that I had time to write this whole post.
        i*          #Boss isn't even watching. Maybe I'll do another later.
          );        #Remove the last _, since we've one too many.
            "l"     #lmao backslashes

And that's everything! Why don't you check my work by trying it out online? 78 is the max size you can get before it starts to linebreak on TIO on my monitor, try to find yours!

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ This looks great! Good job! +1 \$\endgroup\$ – RGS Feb 21 at 23:39
  • \$\begingroup\$ Ping me when it's sub 60 :) \$\endgroup\$ – RGS Feb 21 at 23:40
  • \$\begingroup\$ I found this on Stack Overflow: stackoverflow.com/questions/60342178/… (no answers, though) (and it's by you) \$\endgroup\$ – S.S. Anne Feb 22 at 2:46
1
\$\begingroup\$

Clojure (307 bytes)

Great challenge, because it let me crank up Def Leppard's "Rocket" and Elton John's "Rocket Man" while coding. Always a plus! :-)

Golfed:

(defn r[n s](apply str(repeat n s)))(defn b[n](r n \ ))(defn p[s](println s))(defn k[n](let[t(str \*(r(inc (* n 2))\-)\*)](p(str(b(inc n))\|))(doseq[l(range 0 n)](p(str(b(- n l))\/(b(inc(* 2 l)))\\)))(p t)(doseq[l(range 1 (inc(* n 2)))](p(str "| "(r n "o ")\|)))(p t)(p(str " /"(r(inc(* 2(dec n)))\_)\\))))

Try it online!

Ungolfed:

(defn repeat-str [n s]
  (apply str (repeat n s)))

(defn blanks [n]
   (repeat-str n \ ))

(defn rocket [n]
  (let [ top-bottom  (str \* (repeat-str (inc (* n 2)) \-) \*) ]
    (println (str (blanks (inc n)) \|))
    (doseq [ l  (range 0 n) ]
      (println (str (blanks (- n l)) \/ (blanks (inc (* 2 l))) \\)))
    (println top-bottom)
    (doseq [ l  (range 1 (inc (* n 2))) ]
      (println (str "| " (repeat-str n "o ") "|")))
    (println top-bottom)
    (println (str " /"  (repeat-str (inc (* 2 (dec n))) \_) \\))))

GUITAR..! DRUMS..!

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Thanks for your submission! +1 I'm glad you enjoyed the challenge! \$\endgroup\$ – RGS Feb 26 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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