66
\$\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
\$\begingroup\$

Perl, 65 60 bytes

say'  |
 /_\\';say" |$_|"for split'',<>;say' |_|
/___\
 VvV'

Needs -E to use say, input should be piped in in order to not have a trailing newline. Notice that there's a space at the beginning of the second and fourth lines. Takes advantage of being able to use literal new lines in Perl to save a byte over using \n in each of the cases

Thanks to @manatwork for saving 5 bytes!

\$\endgroup\$
6
  • \$\begingroup\$ I'm afraid you did the same mistake as I did – you forgot the |_|. \$\endgroup\$
    – manatwork
    Aug 26, 2016 at 18:21
  • \$\begingroup\$ @manatwork Nope! the s/\n/_/ adds it in since input in Perl comes with a new line character at the end, I'm swapping it for the underscore and it's handled as an additional character in the loop \$\endgroup\$ Aug 26, 2016 at 18:22
  • \$\begingroup\$ Strange. I get the output without it: pastebin.com/QB2qMuSE Oh, I see, this is newline dependent. As the question owner wrote that will be no newline in input, I tried without. \$\endgroup\$
    – manatwork
    Aug 26, 2016 at 18:26
  • \$\begingroup\$ Oh! Instead of piping in the input, execute the file and then type the input (followed by pressing enter to end the input). The enter from that is what gets translated to the _. Alternately, replace the first newline with $ in order to be able to pipe in input (but not enter it manually) for the same byte count \$\endgroup\$ Aug 26, 2016 at 18:29
  • \$\begingroup\$ Interesting choice, given it would be shorter without that newline handling: pastebin.com/QXRFdJwU \$\endgroup\$
    – manatwork
    Aug 26, 2016 at 18:37
1
\$\begingroup\$

MUMPS: 94 bytes

To get some more variety in here. I tried to solve this in C by declaring main as an array of integers that were compiled machine code but it was still too big, especially on a 64 bit machine.

r
 r x w !,"  |",!," /_\",! f i=1:1:$L(x) w " |",$E(x,i),"|",!
 w " |_|",!,"/___\",!," VvV" q
\$\endgroup\$
1
\$\begingroup\$

MATL, 47 42 41 bytes

95h"' |'@yPhh]v'   /|_ \'2ew'/ _V_v_V\'2e

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Clojure (83 bytes)

#(str "  |\n /_\\\n |" (clojure.string/join "|\n |" (str % \_)) "|\n/___\\\n VvV")

And here's a rocket for you:

  |
 /_\
 |W|
 |e|
 |l|
 |c|
 |o|
 |m|
 |e|
 | |
 |t|
 |a|
 | |
 |E|
 |a|
 |r|
 |f|
 |_|
/___\
 VvV
\$\endgroup\$
1
\$\begingroup\$

Javascript (ES5), 109 89 Bytes)

function(n){s=" |\n /_\\\n |";for(i=0;c=n[i++];)s+=c+"|\n |";return s+"_|\n/___\\\n VvV"}

Ungolfed:

function a(n){
var str="  |\n /_\\\n";
for(var i=0;i<n.length;i++){
str+=" |"+n[i]+"|\n";
}
return str+" |_|\n/___\\\n VvV";
}

EDIT: Saved 20 Bytes thanks to manatwork!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You have a small bug: the flame is not centered. That will cost you 1 character, but there are a couple of them you can remove: user shorter variable name; do not enclose the single instruction repeated by for in braces; increment the counter when you use it, instead of for's 3rd parameter; rearrange the strings to use a single string literal in the loop; test whether string end is reached by current character, not by .length; and anonymous functions are acceptable: function(n){s=" |\n /_\\\n |";for(i=0;c=n[i++];)s+=c+"|\n |";return s+"_|\n/___\\\n VvV"}. \$\endgroup\$
    – manatwork
    Aug 27, 2016 at 15:20
1
\$\begingroup\$

Java 8, 132 109 107 96 Bytes

i->"  |\n /_\\ \n"+i.chars().mapToObj(c->" |"+(char)c+"|")
                            .collect(joining("\n"))+"\n |_|\n/___\\\n VvV"
\$\endgroup\$
3
  • \$\begingroup\$ How do you run this? This doesn't seem to be a complete method... \$\endgroup\$
    – jobukkit
    Aug 30, 2016 at 16:22
  • 2
    \$\begingroup\$ @JopV. Yes it's a lambada expression, this is a Function<String, String> in Java-8 to be applied on any string value. Correct me if I have mistaken. \$\endgroup\$
    – akash
    Aug 30, 2016 at 16:32
  • \$\begingroup\$ Your submission shouldn't have whitespace added (you can include a separate readable version with spaces). Also it looks like you're using a static import of java.util.stream.Collectors.joining, so that statement should be included in your submission and byte count. And please mention that lambda type in your solution. \$\endgroup\$
    – Jakob
    Aug 29, 2017 at 17:00
1
\$\begingroup\$

Neoscript, 76 bytes

{s|"  |
 /_\\
"+(s as Array):map({e|" |"+e+"|
"}):fuse()+" |_|
/___\\
 VvV"}

{s|...} declare a lambda and as is the casting operator.

\$\endgroup\$
1
\$\begingroup\$

Racket 82 bytes

(display"  |\n /_\\\n")(for((i s))(printf" |~a|~n"i))(display" |_|\n/___\\\n VvV")

Ungolfed:

(define (f s)
  (display "  |\n /_\\\n")
  (for((i s))
    (printf " |~a|~n"i))
  (display" |_|\n/___\\\n VvV"))

Testing:

(f "Racket")

Output: A Rocket by Racket!

  |
 /_\
 |R|
 |a|
 |c|
 |k|
 |e|
 |t|
 |_|
/___\
 VvV
\$\endgroup\$
1
\$\begingroup\$

Python 3, 83 Bytes

s=input("")
print("  | \n /_\\")
for c in s:print(" |"+c+"|")
print("/___\\\n VvV")
\$\endgroup\$
1
1
\$\begingroup\$

Perl 5, 55+1 (-p flag)=56 bytes

s/(.)/\n |$1|/g;$_="  |  \n /_\\ $_ |_| \n/___\\\n VvV"

Takes string as a single line (with trailing newline) from stdin.

\$\endgroup\$
1
\$\begingroup\$

SOGL V0.12, 27 24 bytes

yQŗ4δ⁾≥‘π0ρ9³‘OΓ,{Ƨ |ΚΓO

Try it Here!

\$\endgroup\$
1
\$\begingroup\$

05AB1E, 27 bytes

S'|ì»"|
/_
ÿ
|_
/__
Vv".∞.c

Try it online!

Explanation

S          # Split input into seperate characters
 '|ì»      # Prepend '|' to each and join by newline
     "|    # Half the rocket, where 'ÿ' is replaced by the processed input
/_
ÿ
|_
/__
Vv"
   .∞.c    # Intersected mirror and centralize
\$\endgroup\$
1
\$\begingroup\$

Excel VBA, 105 103 102 84 82 Bytes

Anonymous VBE Immediate Window function that takes input of type Variant/String from cell [A1] and outputs a rocket to the VBE immdiate window

Golfed:

?"  |":?" /_\":For i=0To[Len(A1)]:?" |"Mid([A1&"_"],i+1,1)"|":Next:?"/___\":?" VvV

Output:

[A1]="NASA.XLSM"
?"  |":?" /_\":For i=0To[Len(A1)]:?" |"Mid([A1&"_"],i+1,1)"|":Next:?"/___\":?" VvV
  |             '  <- Output
 /_\
 |N|
 |A|
 |S|
 |A|
 |.|
 |X|
 |L|
 |S|
 |M|
 |_|
/___\
 VvV
\$\endgroup\$
1
\$\begingroup\$

Jstx, 42 bytes

♀◘ááⁿ▄εá»▀▄84♀☺áⁿE►âD85♀►áⁿ▀ⁿ▄ε»▀▀▀▄▄εá╓÷╓

Explanation

♀◘ááⁿ▄εá»▀▄         # Push literal   |\n /_\
8                   # Print the first stack value, then a newline.
4                   # Enter an iteration block over the first stack value and push the iteration element register at the begining of each loop.
♀☺áⁿ                # Push literal  |
E                   # Push the difference of the second and first stack values.
►â                  # Push literal |
D                   # Push the sum of the second and first stack values.
8                   # Print the first stack value, then a newline.
5                   # End an iteration block.
♀►áⁿ▀ⁿ▄ε»▀▀▀▄▄εá╓÷╓ # Push literal  |_|\n/___\\n VvV

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Python 3.7, 79 77 Bytes

o='  | \n /_\\\n'
for c in input()+"_":o+=f' |{c}|\n'
print(o+'/___\\\n VvV')

-2 bytes thanks to Value Ink

\$\endgroup\$
1
  • \$\begingroup\$ Welcome to PPCG! I think you can save 2 bytes by iterating through input()+"_" so you don't have to manually put in the bottom of the rocket shaft. Try it online! \$\endgroup\$
    – Value Ink
    Jul 27, 2019 at 0:35
1
\$\begingroup\$

Oracle SQL, 77 bytes

select'  |
 /_\
'||regexp_replace(x,'(.)',' |\1|
')||' |_|
/___\
 VvV'from t;

It works with an assumption that input string is stored in a table t(x), e.g.

with t(x) as (select 'Earth' from dual)

Test in SQL*Plus

SQL> set pages 0
SQL> with t(x) as (select 'Earth' from dual)
  2  select'  |
  3   /_\
  4  '||regexp_replace(x,'(.)',' |\1|
  5  ')||' |_|
  6  /___\
  7   VvV'from t;
  |
 /_\
 |E|
 |a|
 |r|
 |t|
 |h|
 |_|
/___\
 VvV
\$\endgroup\$
1
\$\begingroup\$

Pip, 71 69 64 61 bytes

f:"|"u:C95Ps.s.fP" /_\"Fi,#a{[email protected]}P" |_|"P"/___\"" VvV"

Try it online!

[Try it online!][TIO-jyx4p3hj]

f:"|"
u:C95
a:q
Ps.s.f
P" /_\"
F i ,#a{
    [email protected]     make the fuselage
}
P" |_|"
P"/___\"
" VvV"

nothing fancy happening here.

\$\endgroup\$
1
\$\begingroup\$

C#, 159 bytes

public class P{public static void Main(string[]a){var f="";foreach (char c in a[0]){f+=" |"+c+"|\n";}System.Console.Write(@"  |
 /_\
"+f+@" |_|
/___\
 VvV");}}

Try Online

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Suggest foreach(var c in a[0])f+=" |"+c+"|\n"; instead of foreach (char c in a[0]){f+=" |"+c+"|\n";} \$\endgroup\$
    – ceilingcat
    Aug 15, 2020 at 16:55
1
\$\begingroup\$

Ruby, 85 bytes

puts"  |\n /_\\";gets.split('').append('_').each{|a|puts" |#{a}|"};puts"/___\\\n VvV"

Attempt This Online!

\$\endgroup\$
1
  • \$\begingroup\$ 70 bytes \$\endgroup\$
    – naffetS
    Apr 30, 2022 at 15:11
1
\$\begingroup\$

Google Sheets, 61 59 Bytes

Anonymous worksheet function that takes input from range [A1] and outputs a rocket to the calling cell

="  |
 /_\
"&RegExReplace(A1&"_","(.)"," |$1|
")&"/___\
 VvV

Example Output given [A1]="Google

  |
 /_\
 |G|
 |o|
 |o|
 |g|
 |l|
 |e|
 |_|
/___\
 VvV
\$\endgroup\$
0
\$\begingroup\$

JavaScript 63

s=>`  |\n /_\\\n${(s+'_').replace(/./g," |$&|\n")}/___\\\n VvV`

executed using s("test") for example.

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

SpecBAS - 95 bytes

1 input a$: ?"  |"'" /_\"
2 for i=1 to len a$:? " |";a$(i);"|":next i
3 ?" |_|"'"/___\"'" VvV"

The apostrophe moves the cursor down a line, and ? is shorthand for PRINT

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

GNU sed, 53 bytes

1i\  |\n /_\\
s:.: |&|\n:g;s:$: |_|:g;$a\/___\\\n VvV

With GNU sed, you can omit the initial \ for the a command, so it is one byte less:

1i\  |\n /_\\
s:.: |&|\n:g;s:$: |_|:g;$a/___\\\n VvV
\$\endgroup\$
0
\$\begingroup\$

R, 148 bytes

f=function(b){cat("  |\n /_\\\n |",paste(as.character(unlist(strsplit(c(b,"_"),''))),collapse='|\n |'),"|\n/___\\\n VvV",sep="")}
f(commandArgs(T))

If above code is in sample.R file then run from command line

Rscript sample.R "GOKUL"

Output:

  |
 /_\
 |G|
 |O|
 |K|
 |U|
 |L|
 |_|
/___\
 VvV 
\$\endgroup\$
0
0
\$\begingroup\$

sed, 51 bytes

s/$/_/
s/./ |&|\n/g
s!.*!  |\n /_\\\n&/___\\\n VvV!

Each line from stdin produces a new rocket on stdout.

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

Dart, 110 106 bytes

r(var s){s=s+'_';var o='  |\n /_\\\n',i=0;while(i<s.length)o=o+' |'+s[i++]+'|\n';return o+'/___\\\n VvV';}

Try it out

EDIT: Saved 4 bytes, thanks!

\$\endgroup\$
4
  • \$\begingroup\$ Do not declare i separately as int, just enumerate it at var. \$\endgroup\$
    – manatwork
    Aug 30, 2016 at 16:15
  • \$\begingroup\$ @manatwork What do you mean? How would you not have to declare i? \$\endgroup\$
    – jobukkit
    Aug 30, 2016 at 16:25
  • \$\begingroup\$ You have, but var is fine for i too: var o=' |\n /_\\\n',i=0. \$\endgroup\$
    – manatwork
    Aug 30, 2016 at 16:38
  • \$\begingroup\$ Ah, thanks! I didn't know Dart had that! \$\endgroup\$
    – jobukkit
    Aug 30, 2016 at 17:06
0
\$\begingroup\$

dc, 55 bytes

Building a rocket with the desck calculator:

?[  |
 /_\
]n[[ |]nn[|
]nz0<R]sRz0!=R[ |_|
/___\
 VvV]p

Because dc interprets input as commands, our string's characters are assumed to be already on the stack and the code is acting more like a function accessing its arguments.

Example run:

me@LCARS:/PPCG$ dc -f rocket_science.dc
[A][S][A][N] #the stack is LIFO, so the arguments (characters) are in reverse order
  |
 /_\
 |N|
 |A|
 |S|
 |A|
 |_|
/___\
 VvV
\$\endgroup\$
0
\$\begingroup\$

RProgN, 59 Bytes

'  |
 /_\' p '.' ' |%1|
' R "
$" '' R p ' |_|
/___\
 VvV' p

Explination

'  |        #
 /_\'       # Build the top of the rocket
p           # Print it.
            # Input is taken implicitly.
'.' ' |%1|  # v
' R         # Replace each character with " |ITSELF|" followed by a newline.
"           # v
$" '' R  # Snip the last newline.
p           # Print the new body.
            #
' |_|       #
/___\       #
 VvV'       # Build the lower segment.
 p          # Print.

Try it Online!

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

Crystal, 89 bytes

x=gets.to_s.chomp;y="  |
 /_\\
";x.each_char{|c|y+=" |#{c}|
"};puts y+" |_|
/___\\
 VvV"

Ungolfed:

input = gets
if !input
  STDERR.puts "Couldn't get input from stdin!"
  exit 1
end
puts <<-'END'
  |
 /_\
END
input.chomp.each_char do |char|
  puts " |#{char}|\n"
end
puts <<-'END'
/___\
 VvV
END

Example usage

Input: Hello, world!

Output:

  |
 /_\
 |H|
 |e|
 |l|
 |l|
 |o|
 |,|
 | |
 |w|
 |o|
 |r|
 |l|
 |d|
 |!|
 |_|
/___\
 VvV
  • Actual newlines instead of \n to save 1 byte per newline
  • String#each_char instead of String#chars.each to save 1 byte
  • Temporary y variable instead of multiple puts calls to save a few bytes
  • As Crystal is statically typed and gets can return nil, I had to find a way to workaround that. not_nil! raises an exception on runtime if the value is nil and otherwise just returns it, however, the Nil class also implements to_s (that returns a 0-length string) which is 4 characters (as opposed to 8). String also implements to_s (just returns itself), so this is a 4 characters shorter way to shut the compiler up.
\$\endgroup\$
0
\$\begingroup\$

Pyth, 44 bytes

js[c2"  |  /_\\"m:" |_|"\_dzc3" |_| /___\ VvV

Try it online!

\$\endgroup\$

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.