59
\$\begingroup\$

Write a program or function that takes in a single-line string. You can assume it only contains printable ASCII. Print or return a string of an ASCII art rocket such as

  |
 /_\
 |E|
 |a|
 |r|
 |t|
 |h|
 |_|
/___\
 VvV

with the input string written from top to bottom on the fuselage. In this case the input was Earth. The height of the rocket (including flames) is always the length of the string plus five.

Each line in the output may have up to two trailing spaces and there may be a single optional trailing newline. The shortest code in bytes wins.

More Examples:

[empty string]

  |
 /_\
 |_|
/___\
 VvV

a

  |
 /_\
 |a|
 |_|
/___\
 VvV

|0

  |
 /_\
 |||
 |0|
 |_|
/___\
 VvV

\/\

  |
 /_\
 |\|
 |/|
 |\|
 |_|
/___\
 VvV

 _ _ [note trailing space]

  |
 /_\
 | |
 |_|
 | |
 |_|
 | |
 |_|
/___\
 VvV

    [4 spaces]

  |
 /_\
 | |
 | |
 | |
 | |
 |_|
/___\
 VvV

SPACEY

  |
 /_\
 |S|
 |P|
 |A|
 |C|
 |E|
 |Y|
 |_|
/___\
 VvV

Leaderboard

var QUESTION_ID=91182,OVERRIDE_USER=26997;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

\$\endgroup\$
  • 1
    \$\begingroup\$ Related. There may be others which are close enough that this counts as a dupe. \$\endgroup\$ – Peter Taylor Aug 26 '16 at 7:15
  • 2
    \$\begingroup\$ @Sefa Spaces yes. No to other whitespace. As the linked wiki indicates. \$\endgroup\$ – Calvin's Hobbies Aug 26 '16 at 7:28
  • 6
    \$\begingroup\$ D'oh, I saw the title and expected something about brain surgery. :( \$\endgroup\$ – user16488 Aug 26 '16 at 11:22
  • 17
    \$\begingroup\$ And if the bottom points at the sky you will not go to space today. \$\endgroup\$ – AstroDan Aug 26 '16 at 17:59
  • 4
    \$\begingroup\$ "It worked in Kerbal Space Program..." \$\endgroup\$ – Magic Octopus Urn Oct 26 '16 at 17:52

101 Answers 101

55
\$\begingroup\$

Excel VBA, 142 179 175 160 155 bytes

Instruction:

Set the worksheet of Excel where cell A1 is input and column C as the output. Set the text alignment in column C to center. Write and run the following code in the Immediate Window:

[C1]="|":[C2]="/_\":T=[A1]&"_":For i=1To Len(T):Cells(i+2,3)="|"&Mid(T,i,1)&"|":Next:Cells(i+2,3)="/__\":Cells(i+3,3)="VvV":[C:C].HorizontalAlignment=-4108

Ungolfed the code:

Sub R()
    [C1] = "|"
    [C2] = "/_\"
    T = [A1]&"_"

    For i = 1 To Len(T)
        Cells(i + 2, 3) = "|" & Mid(T, i, 1) & "|"
    Next

    Cells(i + 2, 3) = "/__\"
    Cells(i + 3, 3) = "VvV"
    [C:C].HorizontalAlignment = -4108   'Set the text alignment in column C to center
End Sub

Output:

enter image description here

Note: The font and the color are just a personal choice.


15 bytes saved due to edc65's suggestion. Thanks.

5 bytes saved due to TaylorScott's suggestion. Thanks.

\$\endgroup\$
  • \$\begingroup\$ Save 15 bytes adding "_" to T. Like this [C1]="|":[C2]="/_\":T=[A1]&" ":For i=1To Len(T):Cells(i+2,3)="|"&Mid(T,i,1)&"|":Next:Cells(i+2,3)="/__\":Cells(i+4,3)="VvV":Columns(3).HorizontalAlignment=-4108 \$\endgroup\$ – edc65 Aug 29 '16 at 6:32
  • \$\begingroup\$ (ok there is an error in my code and it's too late to edit it. But you get the idea) \$\endgroup\$ – edc65 Aug 29 '16 at 6:38
  • \$\begingroup\$ @edc65 I don't get the idea. Your code is exactly the same with mine so what should I edit to save 15 bytes? \$\endgroup\$ – Anastasiya-Romanova 秀 Aug 29 '16 at 6:39
  • 1
    \$\begingroup\$ 154 Bytes: [C:C].HorizontalAlignment=-4108:[C1]="|":[C2]="/_\":T=[A1]&"_":For i=1To Len(T):Cells(i+2,3)="|"&Mid(T,i,1)&"|":Next:Cells(i+2,3)="/__\":Cells(i+3,3)="VvV \$\endgroup\$ – Taylor Scott Dec 22 '17 at 14:55
  • 1
    \$\begingroup\$ Or you could get it down to 151 bytes, keeping the centering aspect [C:C].HorizontalAlignment=3:[C1]="|":[C2]="/_\":T=[A1]&"_":For i=1To Len(T):Cells(i+2,3)="|"&Mid(T,i,1)&"|":Next:Cells(i+2,3)="/___\":Cells(i+3,3)="VvV \$\endgroup\$ – Taylor Scott Jul 12 '18 at 14:37
30
\$\begingroup\$

Perl 6, 75 bytes

"  |\n /_\\".say;" |$_|".say for slurp.chomp.comb;" |_|\n/___\\\n VvV".say;
\$\endgroup\$
  • 101
    \$\begingroup\$ slurp.chomp.comb... Perl is weird. \$\endgroup\$ – Mego Aug 26 '16 at 6:31
  • 14
    \$\begingroup\$ SLURP!!! CHOMP!!! COMB!! Here comes the Perl monster! \$\endgroup\$ – stommestack Aug 29 '16 at 20:55
  • \$\begingroup\$ Note that by using a function and concatanation you can cut out a lot: {[~] " |\n /_\\\n",|(" |$_|\n"for $_.comb)," |_|\n/___\\\n VvV"} 65 bytes \$\endgroup\$ – user0721090601 Jul 27 at 21:38
  • \$\begingroup\$ But you can go even lower by borrowing from JS's: tio.run/… \$\endgroup\$ – user0721090601 Jul 27 at 21:45
22
\$\begingroup\$

JavaScript (ES6), 54

Straightforward

x=>`  |
 /_\\
 |${[...x+'_'].join`|
 |`}|
/___\\
 VvV`

Test

f=x=>`  |
 /_\\
 |${[...x+'_'].join`|
 |`}|
/___\\
 VvV`

function update() {
  O.textContent=f(I.value)
}

update()
<input id=I value='hello' oninput='update()'><pre id=O></pre>

\$\endgroup\$
16
\$\begingroup\$

Actually, 40 bytes

"/___\
 VvV",'_o"|
 |"j'|o" |"+"  |
 /_\

Yes, those newlines are supposed to be there.

Try it online!

Explanation:

Newlines are represented by \n for easier formatting

"/___\\n VvV",'_o"|\n |"j'|o" |"+"  |\n /_\
"/___\\n VvV"                                create the bottom of the rocket
             ,'_o                            get input, append a "_" (for the last section before the jets)
                 "|\n |"j                    insert "|\n |" between every pair of characters
                         '|o                 append "|"
                            " |"+            prepend " |"
                                 "  |\n /_\  create the nose cone
\$\endgroup\$
  • 12
    \$\begingroup\$ Your program looks depressingly similar to an exploded rocket. \$\endgroup\$ – corsiKa Aug 29 '16 at 23:24
15
\$\begingroup\$

C, 83, 82 bytes

F(char*c){for(puts("  |\n /_\\");*c;printf(" |%c|\n",*c++));puts(" |_|\n/___\\\n VvV");}

Test main:

int main() {
  F("");
  F("a");
  F("|0");
  F("\\/\\");
  F(" _ _ ");
  F("    ");
  F("SPACEY");
}
\$\endgroup\$
  • 7
    \$\begingroup\$ I worked out my own C solution, and it turned out being exactly yours, character for character. +1 from me. \$\endgroup\$ – Cody Aug 26 '16 at 16:31
  • \$\begingroup\$ On phone and too lazy to SSH, so this is untested, but should work. Saves 2 bytes (if I counted correctly): F(char*c){for(puts(" |\n /_\\");*c;printf(" |%c|\n",*c++),puts(" |_|\n/___\\\n VvV");} \$\endgroup\$ – algmyr Aug 27 '16 at 6:10
  • \$\begingroup\$ @algmyr saves one byte, actually, because the last puts has to be executed only once, not after every printf. But yes, 1 byte saved, yay! \$\endgroup\$ – Stefano Sanfilippo Aug 27 '16 at 8:40
  • \$\begingroup\$ Right. I'll blame that on golfing when I should have been sleeping. \$\endgroup\$ – algmyr Aug 27 '16 at 12:12
  • \$\begingroup\$ Is this not 88 bytes? \$\endgroup\$ – gastropner Dec 29 '17 at 14:35
10
\$\begingroup\$

Python 2, 93 66 62 61 bytes

A FGITW. Can probably be heavily golfed. Suggestions welcome.

Edit: 27 bytes thanks to Mego. 4 bytes thanks to TheBikingViking. 1 byte thanks to user3030010.

Try It Online!

lambda x:r"""  |
 /_\
 |%s|
/___\
 VvV"""%"|\n |".join(x+"_")
\$\endgroup\$
9
\$\begingroup\$

PHP, 73 72 69 62 bytes

  |
 /_\
 |<?=join('|
 |',str_split($argv[1]._))?>|
/___\
 VvV

Takes the string to print on the fuselage as the first argument from the command line when the script is called.

Improvements:

  1. Saved a byte by replacing \n with a real LF newline in the first argument of join.
  2. Saved three more bytes by appending the rocket base with a single underscore to the input
  3. Thanks to Ismael Miguel: Saved 7 more bytes by taking advantage of the fact that PHP used to be the "Hypertext preprocessor" so you can output as much text as you want and start the code somewhere in the middle.

Try it online!

This was fun! :-)

Sample calls:

php rocket.php ""
php rocket.php EARTH
php rocket.php "This is a very long rocket"
\$\endgroup\$
  • \$\begingroup\$ 62 bytes: sandbox.onlinephpfunctions.com/code/… \$\endgroup\$ – Ismael Miguel Aug 26 '16 at 22:15
  • \$\begingroup\$ Nice golfing! I totally forgot about that possibility. Thank you! \$\endgroup\$ – YetiCGN Aug 26 '16 at 22:22
  • \$\begingroup\$ You're welcome. Also, I saved 2 bytes on the first line. You had 2 extra trailing spaces on it. That was something I wasn't expecting to find, I must say. \$\endgroup\$ – Ismael Miguel Aug 27 '16 at 10:09
  • 1
    \$\begingroup\$ I know, that was really dumb but also really hard to spot. I only noticed once I came up with 64 bytes on your improved version and had to find out why. \$\endgroup\$ – YetiCGN Aug 28 '16 at 13:23
8
\$\begingroup\$

brainfuck, 179 bytes

>-[-[-<]>>+<]>-..[->+>++++<<]>>----.<<++++++++++.>.>>>+[-[--<]>>--]<.[-<+<++>>]<<+.---.<,[<<<.>.>.>.<.>,]<<<.[->>>+<<<]>.>.>>+++.<<.>.>>.<...---.<.<<.>>>------.[-<<<+<+>>>>]<<<.<.

Try it online!

\$\endgroup\$
8
\$\begingroup\$

Ruby, 57 55 bytes

-2 bytes by @ValueInk
-5 bytes by assuming that there is no newline in the input, as suggested by @manatwork. Newline-less input can be provided for example with echo -n, like echo -n hey | ruby rocket.rb.

puts'  |
 /_\
 |'+gets.chars*'|
 |'+'|
 |_|
/___\
 VvV'
Old version, assumes newline in input:

Ruby, 62 60 bytes

puts'  |
 /_\
 |'+gets.chop.chars*'|
 |'+'|
 |_|
/___\
 VvV'
\$\endgroup\$
  • \$\begingroup\$ According to the question owner's comment the input will not contain newline character, so you can remove .chop. \$\endgroup\$ – manatwork Aug 26 '16 at 13:11
  • \$\begingroup\$ @manatwork neat, thanks :) \$\endgroup\$ – daniero Aug 26 '16 at 19:54
  • \$\begingroup\$ If you use single quote strings, you should be able to replace both your \\ with \ . (In single quoted strings, characters aren't escaped, except for \'. \$\endgroup\$ – Value Ink Aug 26 '16 at 20:58
7
\$\begingroup\$

Haskell, 58 bytes

f s="  |\n /_\\\n |"++((:"|\n |")=<<s)++"_|\n/___\\\n VvV"
\$\endgroup\$
7
\$\begingroup\$

Retina, 44 37 bytes

7 bytes thanks to Martin Ender.

$
_
.
¶ |$0|
$
¶/___\¶ VvV
^
  |¶ /_\

Try it online!

\$\endgroup\$
  • \$\begingroup\$ leaves a gap on a row at the bottom :( for "Space, the final frontier." \$\endgroup\$ – xQbert Aug 26 '16 at 20:15
  • \$\begingroup\$ @xQbert Works for me, can you attach a TIO link? \$\endgroup\$ – Leaky Nun Aug 27 '16 at 3:36
  • \$\begingroup\$ odd, it works fine for me now... ah my error had a newline at the end. \$\endgroup\$ – xQbert Aug 27 '16 at 16:20
  • \$\begingroup\$ Retina is the only language I know which adding a trailing newline can completely change the program. \$\endgroup\$ – caird coinheringaahing Nov 4 '17 at 16:46
6
\$\begingroup\$

Jelly, 37 36 bytes

;”_⁾ |;ЀŒB;“/___\“ VvV”“  |“ /_\”;Y

Same score as existing entry, but uses a fun new feature - ŒB, the vectorised version of ŒḄ, known as bounce. Bouncing is running through a list to its end and then back x[:-1]+x[::-1] e.g.: bounce("codegolf") == "codegolflogedoc".

-1 byte thanks to Dennis (use the vectorised version of bounce)

How?

;”_⁾ |;ЀŒB;“/___\“ VvV”“  |“ /_\”;Y - argument: a string, S
                        “  |“ /_\”   - the top of the rocket ["  |", " /_\"] 
;”_                                  - concatenate to make S=S+"_"
   ⁾ |;                              - concatenate to make c=" |"+c
       Ѐ                            - map over right argument i.e. for c in S
         ŒB                          - bounce! With vectorisation c[:-1]+c[::-1]
                                       e.g. " |B" -> " |B| "
           ;                         - concatenate with
            “/___\“ VvV”             - the bottom of the rocket ["/___\", " VvV"]
                                  ;  - concatenate the top with everything else
                                   Y - join with line feeds

Test it on TryItOnline

\$\endgroup\$
  • 2
    \$\begingroup\$ ŒB is short for ŒḄ€. \$\endgroup\$ – Dennis Aug 27 '16 at 3:45
6
\$\begingroup\$

Pyke, 40 37 35 bytes

(Updated to work with latest version)

\_+2" ||
"m:"/___\
 VvV"+R"  |
 /_\

Try it here!

\$\endgroup\$
5
\$\begingroup\$

V, 41, 39 bytes

ys$_òlé
òÎá|I |
Hr/$r\YO  |GpX2á_o VvV

Try it online!

Note that for some reason, the online interpreter was producing unexpected results, so I pushed a debug version to the online interpreter that runs a lot slower. It should produce the correct results now.

Since this program contains unprintable characters, here is a hexdump:

0000000: 7973 245f f26c e90a f2ce e17c 4920 7c0a  ys$_.l.....|I |.
0000010: 4872 2f24 725c 594f 2020 7c1b 4770 5832  Hr/$r\YO  |.GpX2
0000020: e15f 6f20 5676 56                        ._o VvV
\$\endgroup\$
  • \$\begingroup\$ Nice but it doesn't handle the spaces in "Space, the final frontier" quite right. \$\endgroup\$ – xQbert Aug 26 '16 at 20:14
5
\$\begingroup\$

R, 163 bytes

v=c();l="\n";for(i in 1:nchar(a<-scan(,"")))v=c(v,paste0(" |",strsplit(a,"")[[1]][i],"|",l,collapse=""));cat("  |",l," /_\\",l,v," |_|",l,"/___\\",l," VvV",sep="")

Ungolfed :

v=c()     #Empty vector
l="\n"    #Line break

for(i in 1:nchar(a<-scan(,"")))                  #For the number of character of the input
    v=c(v, paste0(" |",strsplit(a,"")[[1]][i],"|","\n",collapse=""))
    #This part cut the input into its letters, paste each letter between `|`'s, 
    #and a line break

cat("  |",l," /_\\",l,v," |_|",l,"/___\\",l," VvV",sep="") #Puts everything in the STDOUT,
                                                           #with spaces where needed

I don't really like the fact I had to put some spaces in the last line, but hey !

\$\endgroup\$
5
\$\begingroup\$

PowerShell v2+, 59 55 51 bytes

"  |
 /_\"
$args|% t*y|%{" |$_|"}
" |_|
/___\
 VvV"

Try it online!

Abuses the default Write-Output at end of execution to stick a newline between each element, since these are all just literal strings on the pipeline. The only "tricky" bit is a loop through each element of the input $args as a char-array to get the body of the rocket.

Uses literal newlines as pointed out by ConnorLSW to save some bytes.
-4 more bytes thanks to Veskah.

\$\endgroup\$
  • \$\begingroup\$ you can put actual newlines in the string to save 3, the shell and ise execute fine without the \r \$\endgroup\$ – colsw May 16 '17 at 9:45
  • \$\begingroup\$ t*y trick to save 4 bytes \$\endgroup\$ – Veskah Jul 26 at 13:58
4
\$\begingroup\$

PowerShell, 70 bytes

"  |`n /_\`n$(([char[]]$a|%{" |$_|"})-join("`n"))`n |_|`n/___\`n VvV 

Set $a to input.

If it has to take input other than a variable it can be piped in:

"Hello World"|%{"  |`n /_\`n$(([char[]]$_|%{" |$_|"})-join("`n"))`n |_|`n/___\`n VvV "}

Example:

  |
 /_\
 |H|
 |e|
 |l|
 |l|
 |o|
 | |
 |W|
 |o|
 |r|
 |l|
 |d|
 |_|
/___\
 VvV 
\$\endgroup\$
4
\$\begingroup\$

Mathematica, 50 bytes

"  |
 /_\\
 |"<>(#<>"|
 |"&/@#)<>"_|
/___\\
 VvV"&

Anonymous function. Takes a list of characters as input and returns a string as output.

\$\endgroup\$
4
\$\begingroup\$

PHP, 108 100 88 bytes

-8 bytes thanks to business cat

-12 bytes thanks to YetiCGN

echo'  | 
 /_\\
';foreach(str_split($argv[1])as$c){echo" |$c|
";}echo' |_|
/___\\
 VvV';

pretty straightforward

Ideone

\$\endgroup\$
  • 1
    \$\begingroup\$ You can save a lot of bytes by using foreach(str_split($a)as$c) instead of the other for loop. Also, you could put the $c directly in the string if you use double quotes: echo" |$c| ...."; \$\endgroup\$ – Business Cat Aug 26 '16 at 12:46
  • \$\begingroup\$ @BusinessCat True, thanks the double quotes wasn't working with the array style thought due to the brackets not being interpreted \$\endgroup\$ – Sefa Aug 26 '16 at 13:15
  • \$\begingroup\$ What about regular expression? function f($a){echo' |.␤ /_\\␤',preg_replace('/./',' |$0|␤',$a),' |_|␤/___\\␤ VvV';} \$\endgroup\$ – manatwork Aug 26 '16 at 15:23
  • 1
    \$\begingroup\$ Why even put a function around it? Replacing $a with $argv[1] and running from command line makes it much shorter. \$\endgroup\$ – YetiCGN Aug 27 '16 at 7:26
  • \$\begingroup\$ @manatwork It's probably a valid alternative, but since i don't understand it and it's not the in the same spirit as mine, I will let you post it. \$\endgroup\$ – Sefa Aug 29 '16 at 7:23
4
\$\begingroup\$

C#, 106 97 80 74 bytes

s=>$@"  |
 /_\
 |{string.Join("|\n |",s.ToCharArray())}|
 |_|
/___\
 VvV";

I don't have C# 6 to try the above but I believe it will work

Saved 7 bytes thanks to Kevin Cruijssen

Thanks to manatwork for pointing me in the right direction to save 17 bytes

Saved 6 bytes thanks to milk

\$\endgroup\$
  • \$\begingroup\$ +1. Btw, trailing whitespaces are optional, so you can change it to: using System.Linq;s=>$(" |\n /_\\\n{string.Join("",s.Select(c=>" |"+c+"|\n"))} |_|\n/___\\\n VvV"); (100 bytes) \$\endgroup\$ – Kevin Cruijssen Aug 26 '16 at 12:17
  • 1
    \$\begingroup\$ @KevinCruijssen I was just in the process of updating this after your comments to my previous answer :) Thanks for the help \$\endgroup\$ – TheLethalCoder Aug 26 '16 at 12:21
  • \$\begingroup\$ You can save some characters by using a single string literal inside Select: " |"+c+"|\n"c+"|\n |" together with moving the ` |` from after {} before it. \$\endgroup\$ – manatwork Aug 26 '16 at 13:57
  • \$\begingroup\$ @manatwork I can't seem to get that to work \$\endgroup\$ – TheLethalCoder Aug 26 '16 at 14:02
  • 1
    \$\begingroup\$ New line is 1 byte compared to \n's 2 bytes. So you'll save 5 more bytes by replacing them with new lines. Yes, if you're using Visual Studio then by default new lines will be 2 bytes, but you can open the source file in a hex editor (Visual Studio has one) and delete the carriage return characters. The output will still be the same. \$\endgroup\$ – milk Aug 29 '16 at 21:40
4
\$\begingroup\$

C,  131 , 121 bytes

#define P printf
main(){char s[99],*p=s;gets(s);P("  |\n /_\\\n");while(*p)P(" |%c|\n",*p++);P(" |_|\n/___\\\n VvV\n");}
\$\endgroup\$
  • \$\begingroup\$ You can remove three characters by moving p=s into the initialization, and using p inside scanf : main(){char s[99],*p=s;scanf("%s",p);P(" |\n /_\\\n");while(*p)P(" |%c|\n",*p++);P(" |_|\n/___\\\n VvV\n");} \$\endgroup\$ – Quentin Aug 26 '16 at 12:15
  • \$\begingroup\$ ok.... i don't know why "scanf("%s", &s)" instead of "scanf("%s", s)" print at end the correct result... at end because scanf not gets spaces i prefer the danger gets()... \$\endgroup\$ – RosLuP Aug 26 '16 at 15:55
  • 2
    \$\begingroup\$ Please don't vandalize your posts. Thank you! \$\endgroup\$ – NobodyNada - Reinstate Monica Oct 20 '16 at 17:51
3
\$\begingroup\$

Jelly, 38 37 bytes

;”_“|“|¶”jЀ“  |¶“/_\¶”;K;“/___\¶ VvV

Try it online!

Same idea as with my Pyth answer, but this can probably be golfed.

\$\endgroup\$
3
\$\begingroup\$

05AB1E, 50 47 43 37 bytes

I'_J"  |
 /_\"svy" |ÿ|"}"/___\
 VvV"»

Try it online!

Saved 9 bytes thanks to Adnan.

\$\endgroup\$
  • \$\begingroup\$ String can also accept newlines in 05AB1E :p, like this. \$\endgroup\$ – Adnan Aug 26 '16 at 8:42
  • \$\begingroup\$ @Adnan Nice, thanks! Any idea how to better get around the empty input? \$\endgroup\$ – Emigna Aug 26 '16 at 8:45
  • \$\begingroup\$ I was thinking about an approach with IðJ at the beginning of the program, which also includes the basis of the fuselage. \$\endgroup\$ – Adnan Aug 26 '16 at 8:47
  • \$\begingroup\$ @Adnan Great idea. I tried that with « earlier without much luck. This is much better though. \$\endgroup\$ – Emigna Aug 26 '16 at 8:51
  • \$\begingroup\$ Removing U and replacing X with s also saves a byte :). \$\endgroup\$ – Adnan Aug 26 '16 at 8:55
3
\$\begingroup\$

Kotlin, 68 bytes

{"""  |
 /_\${it.replace(Regex("."),"\n |\$0|")}
 |_|
/___\
 VvV"""}

Pretty straightforward. Uses multiline string and a regex replacement. This is a lambda with (String)->String type. Test:

fun main(args: Array<String>) {
    val function : (String)->String = {"""  |
 /_\${it.replace(Regex("."),"\n |\$0|")}
 |_|
/___\
 VvV"""}
    println(function(" _ _ "))
}
\$\endgroup\$
3
\$\begingroup\$

Gema, 50 characters

\A=  |\n\ /_\\\n
?=\ |?|\n
\Z=\ |_|\n/___\\\n\ VvV

Sample run:

bash-4.3$ echo -n gema | gema '\A=  |\n\ /_\\\n;?=\ |?|\n;\Z=\ |_|\n/___\\\n\ VvV'
  |
 /_\
 |g|
 |e|
 |m|
 |a|
 |_|
/___\
 VvV
\$\endgroup\$
  • 3
    \$\begingroup\$ You're missing the ` |_|` before the base of the rocket I think \$\endgroup\$ – TheLethalCoder Aug 26 '16 at 13:40
  • \$\begingroup\$ Ouch. Dumb miss. Thank you @TheLethalCoder. \$\endgroup\$ – manatwork Aug 26 '16 at 13:48
  • 1
    \$\begingroup\$ +1 for introducing me to a new (to me) (non-golfing) language. \$\endgroup\$ – Jordan Aug 27 '16 at 1:05
3
\$\begingroup\$

BASH 84 70

Saved 14 thanks to manatwork

(cat&&echo _)|sed 's~.~ |&|\n~g;1s~^~  |\n /_\\\n~;$s~$~/___\\\n VvV~'

Over half of the bytes are for adding the nose, and engine.

\$\endgroup\$
  • \$\begingroup\$ Why the grep? (cat&&echo _)|sed 's~.~ |&|\n~g;1s~^~ |\n /_\\\n~;$s~$~/___\\\n VvV~'. Actually I see no reason to use cat and echo either. Would be shorter transformed into pure sed solution. \$\endgroup\$ – manatwork Aug 26 '16 at 15:00
  • \$\begingroup\$ With pure sed, you don't get any output if you don't have input \$\endgroup\$ – Riley Aug 26 '16 at 15:17
  • \$\begingroup\$ Doh. You are right. Sorry, I forgot that part of requirement. \$\endgroup\$ – manatwork Aug 26 '16 at 15:26
  • \$\begingroup\$ @manatwork I forgot about it in my first try too. \$\endgroup\$ – Riley Aug 26 '16 at 15:27
  • \$\begingroup\$ For future reference, avoid using <pre><code> tags. Use 4 spaces preceding the code in the future, as this auto-escapes Markdown formatting. I have maintained the current formatting due to the strikethrough, but you can just leave that in edit history as well for those curious to look at it. \$\endgroup\$ – Addison Crump Aug 26 '16 at 15:41
3
\$\begingroup\$

GolfScript, 61 51 bytes

My first code golf, I hope it is good enough.

"  |
 /_\\
"\1/.,{" |"\(\"|
"\}\*" |_|
/___\\
 VvV"

Explanation

"  |\n /_\\\n"   # Push the rocket's head
\                # Swap the head with the user's string
1/               # The string is converted into an array
.,               # Push array length
{" |"\           # Push the rocket's body and swap
(\               # Array's first element cut out
"|\n"\           # Push rocket's body and swap
}\*              # Repeat for array length times
" |_|\n/___\\\n VvV" # Push rocket's bottom

Try it online!

\$\endgroup\$
3
\$\begingroup\$

Vim, 41 39 bytes

Here the <End> is literally the "End" key.

i <End>_:s/./ |&|\r/g
/___\
 VvVggxo /_\

Unprintables so:

i <End>_^O:s/./ |&|\r/g
/___\
 VvV^[ggxo /_\^[
\$\endgroup\$
3
\$\begingroup\$

GNU sed, 54 49 48 bytes

This was my first answer to a challenge on this site. The solution is simple, mainly printing, so I spent some time making sure that it can't be golfed anymore.

s:.:\n |&|:g
s::  |& /_\\&:
a\ |_|\n/___\\\n VvV

Try it online!

Fast forward half a year later, I rewrote the script, used a trick for good measure and golfed it down to 1 byte shorter. Now that's progress!

Explanation: the pattern space at each step is mentioned for clarity, given the input example "GO"

s:.:\n |&|:g
   # turn each input char into a section of the rocket (\n |G|\n |O|)
s::  |& /_\\&:
   # 's::' is a trick; the search part is actually the one from the previous 's'
   #command, i.e. a char. Only the first char, '\n', the modifier 'g' is not
   #inherited. The replace part is the head of the rocket. (  |\n /_\\n |G|\n |O|)
a\ |_|\n/___\\\n VvV
   # append the tail of the rocket, plus implicit printing at the end

  |
 /_\
 |G|
 |O|
 |_|
/___\
 VvV
\$\endgroup\$
3
\$\begingroup\$

Lua, 83, 92 bytes

function f(x)return' |\n /_\\\n'..x:gsub('(.)',' |%1|\n')..' |_|\n/___\\\n VvV'end

print('  |\n /_\\\n'..(arg[1] and arg[1]:gsub('(.)',' |%1|\n') or '')..' |_|\n/___\\\n VvV')
\$\endgroup\$
  • \$\begingroup\$ If I add no input to your answer. It does not work. \$\endgroup\$ – nolan Aug 26 '16 at 8:51

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.