13
\$\begingroup\$

(inspired by this SO question)

You are given as input a single positive integer n.

In as few characters as possible, output a rocket in ASCII art with a head, a tail, and a body composed of n segments. There should be no trailing spaces or newlines.

The head and the tail of the rocket are always the same for any value of n. The body consists of two different types of segments which alternate. The examples should make the structure of the rocket clear.

Output for n = 1:

     /**\
    //**\\
   ///**\\\
  ////**\\\\
 /////**\\\\\
+=*=*=*=*=*=*+
|\/\/\/\/\/\/|
|.\/\/..\/\/.|
|..\/....\/..|
|../\..../\..|
|./\/\../\/\.|
|/\/\/\/\/\/\|
+=*=*=*=*=*=*+
     /**\
    //**\\
   ///**\\\
  ////**\\\\
 /////**\\\\\

Output for n = 2:

     /**\
    //**\\
   ///**\\\
  ////**\\\\
 /////**\\\\\
+=*=*=*=*=*=*+
|../\..../\..|
|./\/\../\/\.|
|/\/\/\/\/\/\|
|\/\/\/\/\/\/|
|.\/\/..\/\/.|
|..\/....\/..|
+=*=*=*=*=*=*+
|\/\/\/\/\/\/|
|.\/\/..\/\/.|
|..\/....\/..|
|../\..../\..|
|./\/\../\/\.|
|/\/\/\/\/\/\|
+=*=*=*=*=*=*+
     /**\
    //**\\
   ///**\\\
  ////**\\\\
 /////**\\\\\

Output for n = 3:

     /**\
    //**\\
   ///**\\\
  ////**\\\\
 /////**\\\\\
+=*=*=*=*=*=*+
|\/\/\/\/\/\/|
|.\/\/..\/\/.|
|..\/....\/..|
|../\..../\..|
|./\/\../\/\.|
|/\/\/\/\/\/\|
+=*=*=*=*=*=*+
|../\..../\..|
|./\/\../\/\.|
|/\/\/\/\/\/\|
|\/\/\/\/\/\/|
|.\/\/..\/\/.|
|..\/....\/..|
+=*=*=*=*=*=*+
|\/\/\/\/\/\/|
|.\/\/..\/\/.|
|..\/....\/..|
|../\..../\..|
|./\/\../\/\.|
|/\/\/\/\/\/\|
+=*=*=*=*=*=*+
     /**\
    //**\\
   ///**\\\
  ////**\\\\
 /////**\\\\\
\$\endgroup\$
6
\$\begingroup\$

CJam, 67 63 characters

"дȈ鰚㒄å摒四ㄺ뎞椉ᖛⲠ줥葌⌁掗⦠춻锦䎷겲铣굛쮂먲꿡㦺좒轃汁̕뎕갴瓖邻吟㭰戔蟏㳵回㡚钦״脮烮鋉둎邫"6e4b127b:c~

This should work in the online interpreter.

How it works

After pushing the Unicode string, the snippet

6e4b127b:c~

converts the string from base 60000 to base 127, casts to string and evaluates the result.

The code that get executed is the following:

"..."          " A binary string of length 42.                                            ";
122b7b         " Convert from base 122 to base 7.                                         ";
"\n *./\|"f=   " Replace each digits with the corresponding character.                    ";
60/~           " Split into chunks of length 60 and dump the resulting array.             ";
               " The stack now contains the rocket's head and a body half.                ";
[_W%[\]_W%]    " Push an array of the body half and the reversed body half, a reversed    ";
               " copy of that array and collect both array into another one.              ";
Nf*Nf+         " Join each array of body halves separating by LFs and append LFs.         ";
ri:I*           " Repeat the resulting array I := int(input()) times.                     ";
I<W%           " Keep the first I bodies and reverse their order.                         ";
\a_@\++        " Prepend and append the rocket head/tail.                                 ";
'+"=*"6*'+N+++ " Push S := '+=*=*=*=*=*=*+\n'.                                            ";
*              " Join the array of parts, separating by S.                                ";
\$\endgroup\$
  • 1
    \$\begingroup\$ You should really count this in bytes, non? \$\endgroup\$ – Claudiu Oct 9 '14 at 3:10
  • 8
    \$\begingroup\$ @Claudiu: And ruin my score? :P Answers are scored by their length bytes by default, but the question overrides this by saying in as few characters as possible. \$\endgroup\$ – Dennis Oct 9 '14 at 3:12
10
\$\begingroup\$

CJam, 121 bytes

5,{_5\-S*\)_'/*"**"@'\*N}%:A['+"+
"]"=*"6**:Lri:M{M(:M;2,{M+2%:J;3,{:I'|J@2\-'.*I'.*?_J"/\\""\/"?JI)3I-?*\++_+'|N}%}%L}*A

Try it online

Takes the input n via STDIN.

I'll add an explanation at some point later. Basically it's all just a bunch of loops in a very naive way. To alternate between the two different body parts, I've got a nested loop over the part and a loop over 0 and 1. Then I just add the outer iterator and the inner one, and use their parity to decide between upwards or downwards pointing triangle.

\$\endgroup\$
  • \$\begingroup\$ I got a java.util.NoSuchElementException copy + pasting the code (pointing at Lri) \$\endgroup\$ – Claudiu Oct 8 '14 at 14:57
  • \$\begingroup\$ @Claudiu Did you enter an integer in the "input" field? \$\endgroup\$ – Martin Ender Oct 8 '14 at 14:59
  • \$\begingroup\$ Oh yes, that would do it! \$\endgroup\$ – Claudiu Oct 8 '14 at 14:59
5
\$\begingroup\$

Ruby, 203

n,q=$*[0].to_i,"\\/"
h,r,m=1.upto(5).map{|i|(?/*i+"**"+?\\*i).center 14},?++"=*"*6+?+,3.times.map{|i|?|+?.*i+q*(3-i)+?.*(2*i)+q*(3-i)+?.*i+?|}*"\n"
p=m.reverse.tr q,"/\\"
puts h,([r,m,p,r,p,m]*n)[0,3*n],r,h

Ungolfed

I think in this case it's beneficial to have an non-golfed version.

n      = $*[0].to_i
head   = 1.upto(5).map { |i| ("/"*i + "**" + "\\"*i).center 14 }
ridge  = "+" + "=*"*6 + "+"
middle = 3.times.map { |i| "|" + "."*i + "\\/"*(3-i) + "."*(2*i) + "\\/"*(3-i) + "."*i + "|" }.join "\n"
piddle = middle.reverse.tr "\\/", "/\\"

puts head
puts ([ridge,middle,piddle,ridge,piddle,middle]*n)[0,3*n]
puts ridge, head

Explanation

I doubt this is anywhere near efficient, but it was fun nonetheless.

  • Input is taken from ARGV.
  • h contains the "head" and "tail" of the rocket, r contains the "ridges" that separate the different parts of the rocket and m and p are the top and bottom parts of the "body" of the rocket.
  • The body is constructed by cycling through the Array ["ridge", "top of body", "bottom of body", "ridge", "bottom of body", "top of body"] and taking the first 3*n elements.
  • puts makes sure everything gets its own line.
\$\endgroup\$
3
\$\begingroup\$

Python, 120 + 77 + 1 = 198 characters

This ended up being the wrong approach, but I had already finished when Martin posted his answer.

H,L,T,B=open("R","rb").read().decode('zip').split("X")
n=input()
for p in[H]+([B,T,L,T,B,L]*n)[:3*n][::-1]+[L,H]:print p

Requires a file R (+1 for filename) of 77 bytes, which you can generate as follows:

>>> open('R','wb').write('eJxNjMENwDAIA/+ZIm8i4Qm6Bw+PwvDFQRUFydwJwd5VMOO6ILqIRjE+LsEI4zw2fSKJ6Vzpmt4p\ndVlnRikoVWqrK+8s/X1ivozIJuo=\n'.decode('base64'))
\$\endgroup\$
3
\$\begingroup\$

JS, WIP, 252b or 173 chars

It's not a function, so you have to set the value of n at the beginning (3 here), then execute it in the console or in nodeJS.

Here's the 252b version:

n=3;r=a="     /**01    //**001   ///**0001  ////**00001 /////**00000";b="1+=*=*=*=*=*=*+1";for(c=[d="|0/0/0/0/0/0/|1|.0/0/..0/0/.|1|..0/....0/..|",d.split("").reverse().join("")];n--;)r+=b+c[n%2]+1+c[1-n%2];(r+b+a).replace(/0/g,"\\").replace(/1/g,"\n")

And here's the 173 chars version (using http://xem.github.io/obfuscatweet/)

n=3;eval(unescape(escape('𬠽𨐽𘠠𘀠𘀠𛰪𚠰𜐠𘀠𘀯𛰪𚠰𜀱𘀠𘀯𛰯𚠪𜀰𜀱𘀠𛰯𛰯𚠪𜀰𜀰𜐠𛰯𛰯𛰪𚠰𜀰𜀰𘠻𨠽𘠱𚰽𚠽𚠽𚠽𚠽𚠽𚠫𜐢𞱦𫱲𚁣👛𩀽𘡼𜀯𜀯𜀯𜀯𜀯𜀯𯀱𯀮𜀯𜀯𛠮𜀯𜀯𛡼𜑼𛠮𜀯𛠮𛠮𜀯𛠮𯀢𛁤𛡳𬁬𪑴𚀢𘠩𛡲𩑶𩑲𬱥𚀩𛡪𫱩𫠨𘠢𚑝𞱮𛐭𞰩𬠫👢𚱣𦱮𙐲𧐫𜐫𨱛𜐭𫠥𜡝𞰨𬠫𨠫𨐩𛡲𩑰𫁡𨱥𚀯𜀯𩰬𘡜𧀢𚐮𬡥𬁬𨑣𩐨𛰱𛱧𛀢𧁮𘠩').replace(/uD./g,'')))
\$\endgroup\$
  • \$\begingroup\$ Tested in console. Cool and +1, but usually when the OP asks for an output and not a just return value, an output statement is requested (like console.log or alert - I don't know in nodeJS). \$\endgroup\$ – edc65 Oct 8 '14 at 21:10
  • \$\begingroup\$ you're right... I allowed myself to consider the console as an output. :p (also, nodeJS can only output on its console afaik) \$\endgroup\$ – xem Oct 9 '14 at 7:22
3
\$\begingroup\$

JavaScript (E6) 252 257

Overuse of string.repeat

F=p=>{
  R=(n,s='.',a='')=>a+s.repeat(n)+a;
  for(i=f=o=m=n='';++i<6;)
    o+=f+R(6-i,' ')+R(i,u='/')+'**'+R(i,t='\\'),
    f='\n',
    i<4?m+=f+R(2,R(4-i,t+u,R(i-1)),'|',n+=f+R(2,R(i,u+t,R(3-i)),'|')):0;
  s=f+R(6,'=*','+'),
  console.log(o+s+R(p&1,q=m+n+s)+R(p/2,n+m+s+q)+f+o)
}
\$\endgroup\$
  • \$\begingroup\$ it's fun, we both have 252b but with completely different approaches :) \$\endgroup\$ – xem Oct 9 '14 at 7:20
3
\$\begingroup\$

Javascript (ES3): 243 219 bytes

R=function(n){for(a='',i=5;i--;t=a+=s+'\n')for(s='**',j=6;j--;b=['|../\\..|./\\/\\.|/\\/\\/\\','|\\/\\/\\/|.\\/\\/.|..\\/..'])s=i<j?'/'+s+'\\':' '+s+' ';for(;a+='+=*=*=*=*=*=*+\n',n;)a+=(b[n&1]+b[--n&1]).replace(/[^|]+/g,'$&$&|\n');return a+t}
\$\endgroup\$
  • \$\begingroup\$ 1:SyntaxError: function statement requires a name, 2:incorrect output, the body segments ahould not be all equal (odd and even are different) \$\endgroup\$ – edc65 Oct 9 '14 at 9:11
  • \$\begingroup\$ 1. That's because it's intended to be FunctionExpression. But I've added an assignment, so it should work now. 2. Thanks! I didn't notice that at first. \$\endgroup\$ – subzey Oct 9 '14 at 9:29

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.