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

108 Answers 108

3
\$\begingroup\$

Charcoal, 22 bytes

↷¦|_θ__←v↖V→/↑_↑⊕Lθ/‖B

Try it online!

Needs trailing newline in input, due to how Charcoal input works.

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

V, 47 46 39 37 35 bytes

A_Ó./ |&|\r
a/___\
 VvVHO  |
 /_\

Try it online!

This is my first time trying to golf something. There is probably room for improvement since I don't know V, only vim.

Hexdump:

00000000: 415f 1bf3 2e2f 207c 267c 5c72 2f67 0a61  A_.../ |&|\r/g.a
00000010: 2f5f 5f5f 5c0a 2056 7656 1b48 4f20 207c  /___\. VvV.HO  |
00000020: 0a20 2f5f 5c                             . /_\
\$\endgroup\$
1
  • 3
    \$\begingroup\$ Welcome to PPCG! \$\endgroup\$ Dec 22, 2017 at 14:37
3
\$\begingroup\$

Excel 2016+, 73 bytes

An anonymous worksheet function that takes input from cell A1 and outputs to the calling cell

="  |
 /_\
 |"&Concat(Mid(A1,Sequence(Len(A1)),1)&"|
 |")&"_|
/___\
 VvV"
\$\endgroup\$
3
\$\begingroup\$

C, 128 97 94 bytes

#define P printf(
r(char*s){for(P"  |\n /_\\\n");*s;P" |%c|\n",*s++));P" |_|\n/___\\\n VvV");}

Un-golfed:

#define P printf(
/* Knock off a few bytes by abusing the preprocessor */

r(char*s) { /* Function r (for rocket) accepting a string */
    for( /* For loop */
        P "  |\n /_\\\n"); /* BEFORE entering loop, print the top part */
        *s; /* Loop until the null at the end of the string is encountered */
        P " |%c|\n",*s++) /* Print a middle section for each char */
    );
    P " |_|\n/___\\\n VvV"); /* Print the bottom part */
}

After realizing that I have completely forgotten about puts() due to its usual uselessness (I always use printf()), I finally got it under 90 bytes, only to realize that someone else had beaten me to it:

r(char*s){for(puts("  |\n /_\\");*s;printf(" |%c|\n",*s++));puts(" |_|\n/___\\\n VvV");}
\$\endgroup\$
1
  • \$\begingroup\$ Welcome to Code Golf, and nice answer! \$\endgroup\$ Apr 30, 2022 at 19:42
3
\$\begingroup\$

Vyxal C, 30 24 bytes

`|/__`:ḣṫ⁰p\|vp÷„Ḣ‛VvWøM

Try it Online!

-5 bytes thanks to allxy

How?

`|/__`:ḣṫ⁰p\|vp÷„Ḣ‛VvWøM
`|/__`                     # Push string "|/__"
      :                    # Duplicate
       ḣ                   # Head extract, push a[0] and a[1:]
        ṫ                  # Tail extract, push a[:-1] and a[-1] (stack: a[0], a[1:-1], a[-1])
         ⁰p                # Prepend the input to this a[-1]
           \|vp            # For each character, prepend "|"
               ÷           # Dump, push all contents to the stack
                „          # Rotate stack left once
                 Ḣ         # Remove head
                  ‛Vv      # Push string "Vv"
                     W     # Wrap stack into a list
                      øM   # Flip brackets and palindromise each
                           # C flag centers and joins on newlines
\$\endgroup\$
1
  • \$\begingroup\$ 28 and you can save more with the C flag. \$\endgroup\$
    – allxy
    Apr 30, 2022 at 22:24
2
\$\begingroup\$

Scala, 97 94 77 bytes

print("  |\n /_\\\n"+args(0).map{" |"+_+"|\n"}.mkString+" |_|\n/___\\\n VvV")
\$\endgroup\$
2
\$\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\$
2
\$\begingroup\$

S.I.L.O.S, 157 154 143 bytes

pL   |
def p print : lbl L Line
pL  /_\
loadL :
a = 256
:a
x = get a
if x c
GOTO e
:c
p  |
pChar x
pL |
a + 1
if x a
:e
pL  |_|
pL /___\
p  VvV

It should be fairly readable. Feel free to try it online!

\$\endgroup\$
3
  • \$\begingroup\$ @LeakyNun :( just out of curiosity how can you see null bytes so I can self-debug next time. \$\endgroup\$ Aug 26, 2016 at 16:41
  • \$\begingroup\$ @LeakyNun oh ok, I found the issue. Its all fixed up now \$\endgroup\$ Aug 26, 2016 at 16:47
  • \$\begingroup\$ 143 bytes \$\endgroup\$
    – Leaky Nun
    Aug 26, 2016 at 17:37
2
\$\begingroup\$

R, 116 bytes

Golfed

write(c("  |"," /_\\",sapply(strsplit(scan(,""),"")[[1]],function(y)paste0(" |",y,"|"))," |_|","/___\\"," VvV"),1,1)

Ungolfed

write(                                             # Write to console
      x = c("  |"," /_\\",                         # Add in stock rocket part  
        sapply(X = strsplit(scan(,""),"")[[1]],    # Take in rocket part specification, split string, loop over all specs
               FUN = function(y) {                 
                 paste0(" |",y,"|"))               # Custom build rocket body
                },
        " |_|","/___\\"," VvV"),                   # Add stock parts  
      file = 1,                                    # Print to console
      ncolumns = 1)

  |
 /_\
 |s|
 |t|
 |r|
 |s|
 |p|
 |l|
 |i|
 |t|
 |!|
 |_|
/___\
 VvV
\$\endgroup\$
2
\$\begingroup\$

Python 3, 78 75 Bytes

w="  |\n /_\\"
for i in input(): w+="\n |"+i+"|"
w+="\n |_| \n/___\\ \n VvV"
print(w)

Thanks @ValueInk for spotting that I could lose 3 bytes by clearing the input function of arguments.

\$\endgroup\$
2
  • \$\begingroup\$ Asking adding a character to print when asking for input input(">") is wholly unnecessary and you could save bytes by just calling input() \$\endgroup\$
    – Value Ink
    Aug 26, 2016 at 22:06
  • \$\begingroup\$ @ValueInk thanks, I had forgotten that you could leave the input command blank. \$\endgroup\$
    – AvahW
    Aug 26, 2016 at 22:10
2
\$\begingroup\$

Lua, 69 68 bytes

print([[  |
 /_\
]]..(...):gsub('.',' |%0|\n')..[[ |_|
/___\
 VvV]])

Should work with Lua 5.1 - 5.3 (tested with 5.3).

I don't have enough rep to comment on nolan's answer, but this is quite similar.

I'm using [[long string]] syntax to save a few bytes by avoiding needing to escape newlines and backslashes.

gsub doesn't need to specify a capture because %0 can be used. (Actually, %1 still works without a capture as well, but this isn't strictly documented.)

I also trimmed away the input validation; not sure why it was there -- an empty string input (as opposed to empty input) will work fine. Handling a missing arg[1] can be done more briefly just by (arg[1]or''):gsub(...) anyway, although at this point it is briefer just to switch to io.read() and get the input from stdin. Anyway, ... is a shorter way to get command-line input (even if parens are needed).

\$\endgroup\$
2
\$\begingroup\$

Perl 6, 51 bytes

{"  |
 /_\\
 {("|$_|
"for |.comb,'_')}/___\\
 VvV"}

A lambda that takes a string as argument, and returns a string.

try it online

\$\endgroup\$
2
\$\begingroup\$

Dyalog APL, 50 bytes

↑'/___\' ' VvV',⍨'  |' ' /_\',↓' ','|',⍨'|',⍪⍞,'_'

OK, so it may not be the shortest submission, but it is the only one that carries the name of a real rocket manufacturer:

  |  
 /_\ 
 |A| 
 |P| 
 |L| 
 |_| 
/___\
 VvV 

TryAPL online!

\$\endgroup\$
2
\$\begingroup\$

><>, 60 bytes

'  |'a' /_\'av
a$v?(0:i'|| '<
'r\~'_'$a'/___\'a' VvV
 o>l?!;

Pretty simple really. lots of strings, the newlines are annoying.

Try it online

  |
 /_\
 |>|
 |<|
 |>|
 |_|
/___\
 VvV
\$\endgroup\$
2
\$\begingroup\$

Swift, 99 byte

let f:(String)->String={$0.characters.reduce("  |\n /_\\\n"){$0+" |\($1)|\n"}+" |_|\n/___\\\n VvV"}

Use like this:

print(f("Some String"))

Result:

  |
 /_\
 |S|
 |o|
 |m|
 |e|
 | |
 |S|
 |t|
 |r|
 |i|
 |n|
 |g|
 |_|
/___\
 VvV
\$\endgroup\$
2
\$\begingroup\$

R, 101 bytes

This is an improvement on Frédéric's answer. I eliminated the variable definition, the for-loop, and the need for the sep="" argument.

cat("  |\n /_\\\n",sapply(strsplit(scan(,""),""),function(x)paste0("|",x,"|\n")),"|_|\n/___\\\n VvV")

Ungolfed:

cat("  |\n /_\\\n",                      # Print top of rocket
    sapply(
      strsplit(scan(,""),""),            # Take stdin and convert to list of chars
      function(x)paste0("|",x,"|\n")),   # Print letters
    ,"|_|\n/___\\\n VvV")                # Print bottom and FLAMES

I'm sure that there is still some improvement possible.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Needs " |\n /_\\\n", but never thought about hard coding \n \$\endgroup\$
    – Vlo
    Aug 29, 2016 at 13:27
  • \$\begingroup\$ @Vlo Thanks, that's fixed now. (It is correct in my ungolfed/explained version, so I must have just pasted the wrong version in the first instance. The byte count is unchanged, thankfully.) \$\endgroup\$
    – rturnbull
    Aug 29, 2016 at 22:32
2
\$\begingroup\$

Perl, 51 bytes

50 bytes code + 1 for -p.

s/./$&|
 |/g;s~^~  |
 /_\\
 |~;s~$~_|
/___\\
 VvV~

Usage

perl -pe 's/./$&|
 |/g;s~^~  |
 /_\\
 |~;s~$~_|
/___\\
 VvV~' <<< earth
  |
 /_\
 |e|
 |a|
 |r|
 |t|
 |h|
 |_|
/___\
 VvV
perl -pe 's/./$&|
 |/g;s~^~  |
 /_\\
 |~;s~$~_|
/___\\
 VvV~' <<< ''
  |
 /_\
 |_|
/___\
 VvV
perl -pe 's/./$&|
 |/g;s~^~  |
 /_\\
 |~;s~$~_|
/___\\
 VvV~' <<< '0|'
  |
 /_\
 |0|
 |||
 |_|
/___\
 VvV
\$\endgroup\$
2
\$\begingroup\$

Dart, 80 bytes

g(s)=>'  |\n /_\\\n${s.split('').map((s)=>' |$s|\n').join()} |_|\n/___\\\n VvV';

Running it through

main()=>print(g("Jasper"));

Gives:

  |
 /_\
 |J|
 |a|
 |s|
 |p|
 |e|
 |r|
 |_|
/___\
 VvV
\$\endgroup\$
2
\$\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\$
2
\$\begingroup\$

CJam, 38 bytes

"  |
 /_\
 |"q'_+"|
 |"*"|
/___\
 VvV"

Try it online!

Explanation

Nothing fancy, pretty straightforward.

"  |\n /_\\n |"                              Push the top of the rocket
               q'_+                          Push the input and append an underscore
                   "|\n |"*                  Join the characters of the input with the sides
                           "|\n/___\\n VvV"  Push the bottom of the rocket
\$\endgroup\$
2
\$\begingroup\$

Common Lisp, 85 74 bytes

(lambda(s)(format t"  |
 /_\\
~{ |~a|
~} |_|
/___\\
 VvV"(coerce s'list)))

Try it online!(I added some bytes to call this anonymous function)

For changing part we take input as string.

~{ |~a|         ;we loop through all characters of string
    ~}          ;printing characters from list
(coerce s'list) ;string is converted into list of characters later used by above loop
\$\endgroup\$
2
\$\begingroup\$

Keg, 52 characters

?(\|'\| \
)\\\_\/ \
\|  ^\
 \|\_\|\
\/\_\_\_\\\
 VvV

Only tricky point is that Keg has no strings, the input is pushed to stack character by character. So the processing order is: read input (?) and turn it into middle section, append top section reversed, reverse them all (^), append bottom section.

(Note that the interpreter (TIO implementation?) does not support absolutely no input. Empty input is specified as single newline, which will not be processed anyway.)

Try it online!

\$\endgroup\$
2
\$\begingroup\$

C - 84 Bytes

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

Ungolfed

f(char* s)
{
    puts("  |\n /_\\");

    while(*s)
        printf(" |%c|\n", *s++);

    puts(" |_|\n/___\\\n VvV");
}

Explanation

Function that receives a string prints it into the ascii-rocket. Tested on GCC, generates some warnings if not compiled with -std=c89.

\$\endgroup\$
2
\$\begingroup\$

MathGolf, 36 bytes

ù  |ÿ /_\è'_▐û |\+mñn'/ÿ___\+ÿ VvV]n

Input as a list of characters.

Try it online.

Explanation:

ù  |          # Push string "  |"
ÿ /_\         # Push string " /_\"
è             # Push the inputs as string-array
 '_▐         '# Append a trailing "_"
    û |\+     # Prepend " |" in front of each string
         mñ   # Palindromize each string in the list
           n  # Join it with newline delimiter
'/           '# Push string "/"
  ÿ___\       # Append string "___\": "/___\"
ÿ VvV         # Push string " VvV"
]             # Wrap the entire stack into a list
 n            # Join it with newline delimiter
              # (after which the entire stack is output implicitly)
\$\endgroup\$
2
\$\begingroup\$

K (ngn/k), 65 60 bytes

`0:"  |\n /_\\";{`0:" |",x,"|"}'$1:0;`0:" |_|\n/___\\\n VvV"

Try it online!

-5 bytes thanks to Razetime!

First ever K answer! May not be perfect, but it's pretty good!

Explaination:

`0:"  |\n /_\\" / Print the top of the rocket
{`0:" |",x,"|"} / Print " |$x|"
'$1:0; / For each character in the user input
/ Note: ';' is important because without it
/ the console will also output `(:: :: ...)`
`0:" |_|\n/___\\\n VvV" / Print the end of the rocket
\$\endgroup\$
2
  • \$\begingroup\$ since s is only used once, you can inline it: try it! Also, 0: returns a list of lines, while 1: returns a single string. I've changed that as well. \$\endgroup\$
    – Razetime
    Apr 30, 2022 at 12:44
  • \$\begingroup\$ good job on your first K answer. I will try and give a few more golfing suggestions later. \$\endgroup\$
    – Razetime
    Apr 30, 2022 at 12:58
1
\$\begingroup\$

Batch, 128 bytes

@echo off
set s=%1_
echo   ^|
echo  /_\
:l
echo  ^|%s:~0,1%^|
set s=%s:~1%
if not "%s%"=="" goto l
echo /___\
echo  VvV
\$\endgroup\$
1
\$\begingroup\$

C#, 130 111 95 bytes

s=>{var a="  |\n /_\\\n";foreach(var c in s)a+=" |"+c+"|\n";a+=" |_|\n/___\\\n VvV";return a;};

Saved 16 bytes thanks to Kevin Cruijssen

\$\endgroup\$
1
  • \$\begingroup\$ Trailing whitespaces are optional, so a=" | \n"; can be a=" |\n";. Same applies to a few other lines. Also, why the a+="111";a+="222";a+="333";? You can just do this once: a+="111222333";. Total becomes: s=>{var a=" |\n /_\\\n";for(int i=0;i<s.Length;)a+=" |"+s[i++]+"|\n";return a+" |_|\n/___\\\n VvV";}; (103 bytes) Also, I'm not entirely sure, but isn't a foreach with characters shorter than your for-loop? \$\endgroup\$ Aug 26, 2016 at 12:13
1
\$\begingroup\$

Javascript (using external lib - Enumerable) (84 bytes)

n=>" |\n /_\\\n"+_.From(n).WriteLine(x=>" |"+x+"|")+(n?"\n":'')+" |_|\n/___\\\n VvV"

Link to lib: https://github.com/mvegh1/Enumerable

Code explanation: Pretty straight forward. Just boilerplates the rocketship template (top and bottom), and concats the fuselage string in the middle. Whats eating up a lot of bytes is the check if the input is truthy, because for an empty string it's wrong to add a newline to the beginning of the bottom template

I love how the native JS answer blows this away...

enter image description here

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

Haskell, 67 63 59 bytes

(++"_|\n/___\\\n VvV").("  |\n /_\\\n |"++).(>>=(:"|\n |"))

Thanks to Damien it's now essentially the same as xnor's answer, just in point-free notation. Ideone it!

\$\endgroup\$
1
  • \$\begingroup\$ I never use concatMap. You should use >>= or =<<instead. concatMap f s is the same as f=<<s or s>>=f \$\endgroup\$
    – Damien
    Aug 26, 2016 at 12:00
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

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.