60
\$\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\$ – Hurkyl 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

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\$
  • 3
    \$\begingroup\$ Welcome to PPCG! \$\endgroup\$ – Martin Ender Dec 22 '17 at 14:37
3
\$\begingroup\$

Java 10, 102 99 81 bytes

a->{var r="  |\n /_\\\n |";for(var c:a)r+=c+"|\n |";return r+"_|\n/___\\\n VvV";}

3 bytes saved thanks to @Jules.

Try it online.

Explanation:

a->{                      // Method with character-array parameter and String return-type
  var r="  |\n /_\\\n |"; //  Result-String, starting with the top part:
                          //   |
                          //  /_\
                          //  |
  for(var c:a)            //  Loop over each character in the input-array:
    r+=c                  //   Append the character to the result-String,
        +"|\n |";         //   with trailing:
                          //    |
                          //  |
  return r                //  Return the result-String,
   +"_|\n/___\\\n VvV";}  //  appended with bottom part:
                          //   _|
                          // /___\
                          //  VvV
\$\endgroup\$
  • \$\begingroup\$ Couldn't you make a reference to System.out.println with a shorter name and call that? \$\endgroup\$ – Trey Keown Aug 27 '16 at 0:03
  • 1
    \$\begingroup\$ @Trey Keown System.out.println is part of the test code, not the submission. \$\endgroup\$ – Captain Ford Aug 27 '16 at 1:24
  • 1
    \$\begingroup\$ You can put " |" onto the end of the 'r' initializer, then inside the loop move it to after the appended string, then you don't need at all in the string appended after the loop. I think this would save you 5 bytes. \$\endgroup\$ – Jules Aug 30 '16 at 7:08
  • \$\begingroup\$ @Jules Thanks! Changed it, and it saves 3 bytes (not sure how you got to a save of 5, though). \$\endgroup\$ – Kevin Cruijssen Aug 30 '16 at 7:18
2
\$\begingroup\$

Pyth, 38 bytes

j++"  |
 /_\\"jR_B" |"+Q\_"/___\\
 VvV

Try it online. Test suite.

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

Scala, 97 94 77 bytes

print("  |\n /_\\\n"+args(0).map{" |"+_+"|\n"}.mkString+" |_|\n/___\\\n VvV")
\$\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\$
  • \$\begingroup\$ @LeakyNun :( just out of curiosity how can you see null bytes so I can self-debug next time. \$\endgroup\$ – Rohan Jhunjhunwala Aug 26 '16 at 16:41
  • \$\begingroup\$ @LeakyNun oh ok, I found the issue. Its all fixed up now \$\endgroup\$ – Rohan Jhunjhunwala Aug 26 '16 at 16:47
  • \$\begingroup\$ 143 bytes \$\endgroup\$ – Leaky Nun Aug 26 '16 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\$
  • \$\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 '16 at 22:06
  • \$\begingroup\$ @ValueInk thanks, I had forgotten that you could leave the input command blank. \$\endgroup\$ – sonrad10 Aug 26 '16 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\$
  • 1
    \$\begingroup\$ Needs " |\n /_\\\n", but never thought about hard coding \n \$\endgroup\$ – Vlo Aug 29 '16 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 '16 at 22:32
2
\$\begingroup\$

MATLAB, 94 bytes

@(s)char(['  |';' /_\';arrayfun(@(x)[' |' x '|'],s,'UniformOutput',0)';' |_|';'/___\';' VvV'])

Anonymous function

\$\endgroup\$
  • 2
    \$\begingroup\$ Not sure about MATLAB, but in Octave you can replace false with 0 to save 4 bytes. \$\endgroup\$ – Dennis Aug 30 '16 at 15:54
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\$

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\$
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\$
  • \$\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\$ – Kevin Cruijssen Aug 26 '16 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\$
  • \$\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 '16 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\$
  • \$\begingroup\$ I'm afraid you did the same mistake as I did – you forgot the |_|. \$\endgroup\$ – manatwork Aug 26 '16 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\$ – theLambGoat Aug 26 '16 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 '16 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\$ – theLambGoat Aug 26 '16 at 18:29
  • \$\begingroup\$ Interesting choice, given it would be shorter without that newline handling: pastebin.com/QXRFdJwU \$\endgroup\$ – manatwork Aug 26 '16 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
    \$\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 '16 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\$
  • \$\begingroup\$ How do you run this? This doesn't seem to be a complete method... \$\endgroup\$ – stommestack Aug 30 '16 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\$ – CoderCroc Aug 30 '16 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 '17 at 17:00

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.