65
\$\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\$
8
  • 1
    \$\begingroup\$ Related. There may be others which are close enough that this counts as a dupe. \$\endgroup\$ Aug 26, 2016 at 7:15
  • 2
    \$\begingroup\$ @Sefa Spaces yes. No to other whitespace. As the linked wiki indicates. \$\endgroup\$ Aug 26, 2016 at 7:28
  • 6
    \$\begingroup\$ D'oh, I saw the title and expected something about brain surgery. :( \$\endgroup\$
    – user16488
    Aug 26, 2016 at 11:22
  • 19
    \$\begingroup\$ And if the bottom points at the sky you will not go to space today. \$\endgroup\$
    – AstroDan
    Aug 26, 2016 at 17:59
  • 5
    \$\begingroup\$ "It worked in Kerbal Space Program..." \$\endgroup\$ Oct 26, 2016 at 17:52

109 Answers 109

1 2 3
4
0
\$\begingroup\$

Jq 1.5, 47 bytes

"  |
 /_\\"," |\((./"")[])|"," |_|
/___\\
 VvV"

Expanded

 "  |
  /_\\"             # Head

," |\((./"")[])|"   # Expand |x| with \(interpolation) for each
                    # value from (./"") split of input string by ""
," |_|
 /___\\
  VvV"              # Tail

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Ruby, 53 bytes

->s{'  |
 /_\
 |'+(s+?_).chars*'|
 |'+'|
/___\
 VvV'}

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Bean, 51 bytes

xxd-style hexdump:
00000000: 56d8 8100 d7d0 80c3 cf20 5da3 7800 2080  VØ..×Ð.ÃÏ ]£x. .
00000010: 7b56 5881 0158 8102 a0a0 fc8a a0af dfdc  {VX..X..  ü. ¯ßÜ
00000020: 8aa0 7cfc 8aa0 7cfc 8aaf dfdf dfdc 8aa0  . |ü. |ü.¯ßßßÜ. 
00000030: d6f6 56                                  ÖöV

Try it online!

Equivalent JavaScript (ES6), 51 bytes

`  |
 /_\\
 |${[...a,'_'].join`|
 |`}|
/___\\
 VvV`

Explanation

A full program taking the implicit first line of input as a, it pushes the string '_' onto the array to build the last section of the fuselage. This answer is essentially a compilation of edc65's answer into Bean.

\$\endgroup\$
0
\$\begingroup\$

J, 52 46 45 bytes

2 4|.'___\/','VvV',' |','/_\','|'(,.,.[),&'_'

Try it online!

\$\endgroup\$
0
\$\begingroup\$

><>, 52 bytes

" ||"i:0(?\$a
__/"a$"_"~/>o<"  |"a" /_\"ar"VvV "a"\_

Try It Online

Adds everything to the stack before printing.

\$\endgroup\$
0
\$\begingroup\$

SNOBOL4 (CSNOBOL4), 126 bytes

	OUTPUT('O',6)
	O ='  |'
	O =' /_\'
	S =INPUT '_'
R	S LEN(1) . X REM . S	:F(O)
	O =' |' X '|'	:(R)
O	O ='/___\'
	O =' vVv'
END

Try it online!

Input requires a single trailing newline.

\$\endgroup\$
0
\$\begingroup\$

Yabasic, 86 bytes

A script that takes input from STDIN and output to the console.

Input""s$
?"  |
 /_\\"
For i=0To Len(s$)?" |",Mid$(s$+"_",i+1,1),"|"Next
?"/___\
 VvV"

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ I think you can save three bytes by putting the entire for loop onto one line. \$\endgroup\$ Jul 12, 2018 at 14:48
  • \$\begingroup\$ @JonathanFrech You are absolutely right - I can't believe I missed that. \$\endgroup\$ Jul 12, 2018 at 17:47
0
\$\begingroup\$

Pascal (FPC), 130 bytes

var s:string;c:char;begin writeln('  |'#10' /_\');read(s);for c in s do writeln(' |',c,'|');writeln(' |_|'#10'/___\'#10' VvV')end.

Try it online!

Colouring doesn't work correctly because of \' :)

#10 represents character with ascii code 10 which is a newline.

Basic program flow here: write the top of the rocket, read input, print a row for each character in input (for ... in loop added by FPC), write the bottom of the rocket.

\$\endgroup\$
0
\$\begingroup\$

Perl 5, 46 + 3 (-nlF flag) = 49 bytes

say'  |
 /_\
',(map" |$_|
",@F,_),'/___\
 VvV'

Try it online.

\$\endgroup\$
0
\$\begingroup\$

05AB1E, 25 bytes

'|„/_©¤IìS'|ì`®¤«„Vv».º.c

Try it online or verify all test cases.

Explanation:

'|      '# Push string "|"
„/_      # Push string "/_"
   ©     # Store it in variable `®` (without popping)
¤        # Get the last character of this string (without popping the string itself): "_"
 Iì      # Prepend the input in front of this "_"
         #  i.e. "Bob" → "Bob_"
   S     # Convert it to a list of characters
         #  → ["B","o","b","_"]
    '|ì '# Prepend a "|" in front of each character
         #  → ["|B","|o","|b","|_"]
       ` # Push all those strings separated to the stack
®        # Push variable `®`: "/_"
 ¤«      # Append it's last character to itself: "/__"
„Vv      # Push string "Vv"
»        # Now join all strings on the stack by newlines
         #  → "|
         #     /_
         #     |B
         #     |o
         #     |b
         #     |_
         #     /__
         #     Vv"
 .º      # Intersected mirror this entire string (towards the right)
         #  → "|
         #     /_\
         #     |B|
         #     |o|
         #     |b|
         #     |_|
         #     /___\
         #     VvV"
   .c    # And then centralize the string (adding leading spaces where necessary)
         #  → "  |
         #      /_\
         #      |B|
         #      |o|
         #      |b|
         #      |_|
         #     /___\
         #      VvV"
         # (after which the result is output implicitly)
\$\endgroup\$
0
\$\begingroup\$

SNOBOL4 (CSNOBOL4), 133 bytes

	OUTPUT('O',6)
	O ='  |'
	O =' /_\'
	I =INPUT
S	I LEN(1) . X REM . I	:F(E)
	O =' |' X '|'	:(S)
E	O =' |_|'
	O ='/___\'
	O =' VvV'
END

Try it online!

Always funny to see the shape of the rocket in these answers.

Only interesting thing here is OUTPUT('O',6), which sets O to be the OUTPUT variable into unit number 6, which is STDOUT.

\$\endgroup\$
0
\$\begingroup\$

Python 3, 81 bytes

lambda x:"  |\n /_\\\n%s/___\\\n VvV"%''.join([" |%s|\n"%t for t in list(x+'_')])

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Perl 5, 47 46 + 1 (-n) = 47 bytes

s/./ |$&|
/g;say"  |
 /_\\
$_ |_|
/___\\
 VvV"

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Stax, 25 bytes

æ¢ïÆn£╗ù♂»Σ√m3,^╝}.Σ8Æ╤º⌡

Run and debug it

\$\endgroup\$
0
\$\begingroup\$

perl6 - 69

say "  |\n /-\\\n |{@*ARGS.comb.join("|\n |")}|\n |_|\n/___\\\n VvV"
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Welcome! Consider adding an explanation of your program to those who may not understand it. Also consider adding a link to an online interpreter, such as TIO. Code-only answers are usually automatically flagged as low-quality. \$\endgroup\$
    – mbomb007
    Aug 2, 2019 at 18:12
0
\$\begingroup\$

GolfScript, 53 bytes

"  |\n /_\\"n@0$1/\;{" |"\"|\n"}/" |_|\n/___\\\n VvV"

Try it online!

"  |\n /_\\"n        ascii art
@                    rotate so input is on top
0$1/                 split input into elements of size 1
\;                   swap top elements, pop top (input)
{" |"\"|\n"}/        now the top element is the input array so for each we push the left pipe, swap, then push the right pipe
" |_|\n/___\\\n VvV" ascii art
\$\endgroup\$
0
\$\begingroup\$

33, 75 69 bytes

-6 bytes because I remembered \n is a thing.

"  |\n /_\\"pi1bzst' | |'j[2ktNpNitclz1aztstcjz]" |_|\n/___\\\n VvV"p

Try it online hopefully coming soon

Explanation:

"  |\n /_\\"pi                     | Print the first part of the rocket
-----------------------------------|
1bzs                               | Get the first command-line argument
            j[       clz1aztstcjz] | For each character in it
     t' | |'  2k                   | - Put it in the fuselage "| |"
                NpNi               | - If it is not null, print it (Null checking is due to the way loops work in 33)
-----------------------------------|
" |_|\n/___\\\n VvV"p              | Print the bottom of the rocket
\$\endgroup\$
0
\$\begingroup\$

Python 3, 86 bytes

code-golf:

n=input();print('  |\n / \ ')
for l in n:print(' |'+l+'|')
print(' |_|\n/___\ \n VvV')

normal:

n = input()
print('  |')
print(' / \')

for l in n:
    print(' |' + l + '|')

print(' |_|')
print('/___\')
print(' VvV')
```
\$\endgroup\$
0
\$\begingroup\$

GNU AWK, 74 bytes

BEGIN{RS=".|";print"  |\n /_\\"}END{print" |_|\n/___\\\n VvV"}$0=" |"RT"|"

Try it online!

AWK was made for this kind of problem.

The BEGIN pattern do things before the input is read. Changing the default RS variable to ".|" makes AWK read the input one character at a time (i.e., as the /./ regex).

RT is exclusive to GNU AWK, being the text of the RS captured by the regex.

The END pattern do things after the input is finished.

\$\endgroup\$
1 2 3
4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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