Print the Retro Rocket

13

1

(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:

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

absinthe

Posted 2014-10-08T14:06:26.083

Reputation: 8 359

3

related post, from our nemesis: http://codereview.stackexchange.com/questions/65040/retro-rocket-ascii-art

– None – 2014-10-08T17:51:15.407

Also related. – Doorknob – 2014-10-08T21:08:47.970

Answers

6

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.                                ";

Dennis

Posted 2014-10-08T14:06:26.083

Reputation: 196 637

1You should really count this in bytes, non? – Claudiu – 2014-10-09T03:10:14.160

8@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. – Dennis – 2014-10-09T03:12:41.017

10

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.

Martin Ender

Posted 2014-10-08T14:06:26.083

Reputation: 184 808

I got a java.util.NoSuchElementException copy + pasting the code (pointing at Lri) – Claudiu – 2014-10-08T14:57:57.727

@Claudiu Did you enter an integer in the "input" field? – Martin Ender – 2014-10-08T14:59:07.820

Oh yes, that would do it! – Claudiu – 2014-10-08T14:59:50.483

5

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.

britishtea

Posted 2014-10-08T14:06:26.083

Reputation: 1 189

3

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'))

Claudiu

Posted 2014-10-08T14:06:26.083

Reputation: 3 870

3

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)
}

edc65

Posted 2014-10-08T14:06:26.083

Reputation: 31 086

it's fun, we both have 252b but with completely different approaches :) – xem – 2014-10-09T07:20:16.413

3

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,'')))

xem

Posted 2014-10-08T14:06:26.083

Reputation: 5 523

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). – edc65 – 2014-10-08T21:10:58.190

you're right... I allowed myself to consider the console as an output. :p (also, nodeJS can only output on its console afaik) – xem – 2014-10-09T07:22:28.553

3

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}

subzey

Posted 2014-10-08T14:06:26.083

Reputation: 121

1:SyntaxError: function statement requires a name, 2:incorrect output, the body segments ahould not be all equal (odd and even are different) – edc65 – 2014-10-09T09:11:44.653

>

  • That's because it's intended to be FunctionExpression. But I've added an assignment, so it should work now.
  • Thanks! I didn't notice that at first.
  • < – subzey – 2014-10-09T09:29:43.480