Rock-and-roll founding father Chuck Berry sadly passed away today.

Consider the chorus of his famous song "Johnny B. Goode":

Go, go
Go Johnny go, go
Go Johnny go, go
Go Johnny go, go
Go Johnny go, go
Johnny B. Goode

(There are other ways it has been punctuated but the above will serve for the purposes of the challenge.)

Challenge

Given a nonempty, lowercase string of letters a-z, output the chorus of "Johnny B. Goode" with all the instances of Go or go replaced with the input string, capitalized in the same way.

A trailing newline may optionally follow. Nothing else in the chorus should change.

For example, if the input is code the output must be exactly

Code, code
Code Johnny code, code
Code Johnny code, code
Code Johnny code, code
Code Johnny code, code
Johnny B. Codeode

optionally followed by a newline.

Note that the capitalization of all words matches the original chorus, and (despite lack of rhythm) the Go in Goode is replaced as well as the individual words Go and go.

The shortest code in bytes wins.

Test Cases

"input"
output

"go"
Go, go
Go Johnny go, go
Go Johnny go, go
Go Johnny go, go
Go Johnny go, go
Johnny B. Goode

"code"
Code, code
Code Johnny code, code
Code Johnny code, code
Code Johnny code, code
Code Johnny code, code
Johnny B. Codeode

"a"
A, a
A Johnny a, a
A Johnny a, a
A Johnny a, a
A Johnny a, a
Johnny B. Aode

"johnny"
Johnny, johnny
Johnny Johnny johnny, johnny
Johnny Johnny johnny, johnny
Johnny Johnny johnny, johnny
Johnny Johnny johnny, johnny
Johnny B. Johnnyode

"fantastic"
Fantastic, fantastic
Fantastic Johnny fantastic, fantastic
Fantastic Johnny fantastic, fantastic
Fantastic Johnny fantastic, fantastic
Fantastic Johnny fantastic, fantastic
Johnny B. Fantasticode
share|improve this question
27  
Missed opportunities for test cases: an, c, cath – Neil 2 days ago
36  
Somebody please do a Go version. – jl6 2 days ago
1  
How should the program handle multi-word strings? – SparklePony 2 days ago
3  
Let's just observe a minute or two of silence, and wish Rest In Peace to Chuck. – Erik the Outgolfer 2 days ago
    
@SparklePony The input only contains letters so it will only be one "word" as far as the program knows. – Helka Homba 2 days ago

32 Answers 32

Go, 124 bytes

Go Johnny, Go!

Try it online!

import."strings"
func(s string)string{t,e:=Title(s),", "+s+"\n";m:=t+" Johnny "+s+e;return t+e+m+m+m+m+"Johnny B. "+t+"ode"}
share|improve this answer
6  
The only thing missing is 90 bytes. – Uriel 2 days ago
12  
+1 for using Go – Challenger5 2 days ago

Pure Bash, 69 76 bytes

M=aaaa;echo -e ${1^}, $1 ${M//a/\\n${1^} Johnny $1, $1}\\nJohnny B. ${1^}ode

Try it online!

share|improve this answer
1  
In your try-it-online, it doesn't do the required capitalisation. For example if you feed in code all lower case, you don't get the required capitalisation. – Tom Carpenter 2 days ago
1  
@TomCarpenter Fixed! :) – R. Kap 2 days ago

05AB1E, 37 bytes

™„, ¹J¹Ð™”ÿºÇ ÿ, ÿ”4.D¹™”ºÇ B. ÿode”»

Try it online!

Explanation

™„, ¹J                                # concatenate title-cased input with ", " and input
     ¹Ð™                              # push input, input, title-cased input
        ”ÿºÇ ÿ, ÿ”                    # push the string "ÿ Johnny ÿ, ÿ" with "ÿ" replaced 
                                      # by title-cased input, input, input
                  4.D                 # push 3 copies of that string
                     ¹™               # push title-cased input
                       ”ºÇ B. ÿode”   # push the string "Johnny B. ÿode" with "ÿ" replaced 
                                      # by title-case input
                                   »  # join the strings by newlines
share|improve this answer

VIM, 54 49 Keystrokes (saved 1 keystroke from Kritixi Lithos)

yw~hC<Ctrl-R>", <Ctrl-R>0<Enter>Johnny B. <Ctrl-R>"ode<Esc}O<Ctrl-R>", Johnny <Ctrl-R>0, <Ctrl-R>0<Esc>3.         

Start with the word on a line on a file with the cursor at the first character, then this will replace it all with the text Explanation

  1. Copy the word into a register, then change the first letter to be capitalized and save that to a register.
  2. Write the first line using the registers to fill in the replacements and last lines
  3. Write the second line using the registers to fill in the replacements
  4. Repeat the middle line 3 times

Try it online! (Thanks DJMcMayhem!)

share|improve this answer
    
I think you can do Y instead of yy and maybe even G instead of 2j – Kritixi Lithos 2 days ago
    
And you can do <CR> instead of <esc>o – Kritixi Lithos 2 days ago
    
Also hD works instead of diw – Kritixi Lithos 2 days ago
    
Thanks for the tips! I was able to work in your last one into the current version. I also saved a few more by writing the first and last line in one go, then filling in the middle. – Dominic A. 2 days ago
    
Try it online! – DJMcMayhem 2 days ago

Batch, 207 bytes

@set s= %1
@for %%l in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)do @call set s=%%s: %%l=%%l%%
@set j="%s% Johnny %1, %1"
@for %%l in ("%s%, %1" %j% %j% %j% %j% "Johnny B. %s%ode")do @echo %%~l
share|improve this answer

V, 41 bytes

ä$a, Ùäwa Johnny 5ÄGdwwcWB.W~Aode.ÎvU

Try it online!

The perfect challenge for V!

Explanation:

ä$                              " Duplicate the input ('go' --> 'gogo', and cursor is on the first 'o')
  a, <esc>                      " Append ', '
                                " Now the buffer holds 'go, go'
          Ù                     " Duplicate this line
           äw                   " Duplicate this word (Buffer: 'gogo, go')
             a Johnny <esc>     " Append ' Johnny ' (Buffer: 'go Johnny go, go')
                           5Ä   " Make 5 copies of this line
G                               " Go to the very last line in the buffer
 dw                             " Delete a word
   w                            " Move forward one word (past 'Johnny')
    cW                          " Change this WORD (including the comma), to
      B.<esc>                   "   'B.'
             W                  " Move forward a WORD
              ~                 " Toggle the case of the character under the cursor
               Aode.<esc>       " Apppend 'ode.'
                         ÎvU    " Capitalize the first letter of each line
share|improve this answer
4  
Explanation please? – ckjbgames 2 days ago
    
@ckjbgames Done! – DJMcMayhem yesterday

JavaScript (ES6), 104 101 99 bytes

(i,u=i[0].toUpperCase()+i.slice(1),x=`, ${i}
${u} Johnny `+i)=>u+x+x+x+x+`, ${i}
Johnny B. ${u}ode`

Previous version:

(i,u=i[0].toUpperCase()+i.slice(1))=>u+`, ${i}
${u} Johnny ${i}`.repeat(4)+`, ${i}
Johnny B. ${u}ode`

How it works:

  • It's an anonymous function that takes the input as the parameter i

  • Defines a variable u as the input i with the first letter capitalized (Note that this assumes input is nonempty, which is OK)

  • Just directly construct the string to be returned from those two variables.

  • Repeating the string "go, \nGo Johnny go" four times instead of repeating "Go Johnny go, go" saves one byte.


Edit 1: Forgot to golf out the semicolon, haha!! Also miscounted the bytes, it was originally 102, not 104. Thanks apsillers.

Edit 2: Instead of .repeat(4), by putting that string in a variable x and doing x+x+x+x allows saving two bytes.


Test snippet

let f = (i,u=i[0].toUpperCase()+i.slice(1),x=`, ${i}
${u} Johnny `+i)=>u+x+x+x+x+`, ${i}
Johnny B. ${u}ode`;
<input id=I type="text" size=70 value="code"><button onclick="console.log(f(I.value))">Run</button>

share|improve this answer
    
By the way, I'm new here, I have a question: do the two newlines in my program count as bytes? If not, it's actually 102 bytes, but I think it probably counts... Right? – Hamsteriffic 2 days ago
    
Yep, they each use a byte. – Jonathan Allan 2 days ago
    
I only count 102 bytes here (using mothereff.in/byte-counter), and also there's no need to use a final semicolon, so it's really 101 bytes. – apsillers 16 hours ago
    
@apsillers You're right, I miscounted! And worse, haha I forgot to golf out the semicolon. Thanks. – Hamsteriffic 6 hours ago

Pyth - 52 bytes

j", "_ArBQ3V4s[H" Johnny "G", "G;%"Johnny B. %sode"H

Test Suite.

share|improve this answer

Jelly, 41 bytes

5“ Johnny “, “¶”ẋj¹Ḋṙ7ỴŒu1¦€Y“B. ”⁸Œt“ode

Try it online!

share|improve this answer

C, 156 151 bytes

i,a,b;B(char*s){a=*s++;printf("%c%s, %c%s\n",b=a-32,s,a,s);for(;++i%4;)printf("%c%s Johnny %c%s, %c%s\n",b,s,a,s,a,s);printf("Johnny B. %c%sode",b,s);}
share|improve this answer

Retina, 65 bytes

Byte count assumes ISO 8859-1 encoding.

^
$', 
:T01`l`L
:`,
 Johnny$',
:`$
¶$`
(\S+) (\S+ ).+$
$2B. $1ode

Try it online!

share|improve this answer

Python, 94 bytes

lambda s:("|, #\n"+"| Johnny #, #\n"*4+"Johnny B. |ode").replace("|",s.title()).replace("#",s)
share|improve this answer

Python 3, 88 bytes

lambda x:("{0}, {1}\n"+4*"{0} Johnny {1}, {1}\n"+"Johnny B. {0}ode").format(x.title(),x)

A simple format string, with positional arguments.

share|improve this answer
    
@EricDuminil Thanks. Fixed. – wizzwizz4 2 days ago
1  
@EricDuminil I knew it was at the end of the line, but there was line wrap in the editor window... :-/ – wizzwizz4 2 days ago
    
I'm counting 88 bytes – Felipe Nardi Batista yesterday
1  
@EricDuminil len("\n".__repr__()[1:-2]) is 2. I forgot the __repr__() when measuring the program's length. – wizzwizz4 yesterday
1  
@EricDuminil Only if you wrap it with """ marks instead of " marks. – wizzwizz4 yesterday

C#, 219 211 212 146 Bytes

string x(string a){var b=(char)(a[0]^32)+a.Remove(0,1);var c="Johnny ";return$"{b}, {a}\n{"xxxx".Replace("x",$"{b} {c}{a}, {a}\n")}{c}B. {b}ode";}

Try it online!

Explantation:

    string x(string a) {                            //Method that takes a string as Parameter
    var b = (char)(a[0] ^ 32)                       //Capitalize first letter of "a" 
        + a.Remove(0, 1);                           //append "a" with first letter removed
    var c = "Johnny ";                              //create variable that hold the string "Johnny " 
                                                    //In this example "go" was used as parameter
    return $"{b}, {a}\n                             //Go, go
    {"xxxx".Replace("x", $"{b} {c}{a}, {a}\n")}     //Create a Placeholder that holds "xxxx" 
                                                    //but Replace x with more placeholders and a newline
                                                    //Leading to the result of 4x Go Johnny go, go
    {c}B. {b}ode"; }                               //Johnny B. Goode

Output for testcases:

Go, go
Go Johnny go, go
Go Johnny go, go
Go Johnny go, go
Go Johnny go, go
Johnny B. Goode

Code, code
Code Johnny code, code
Code Johnny code, code
Code Johnny code, code
Code Johnny code, code
Johnny B. Codeode

A, a
A Johnny a, a
A Johnny a, a
A Johnny a, a
A Johnny a, a
Johnny B. Aode

Johnny, johnny
Johnny Johnny johnny, johnny
Johnny Johnny johnny, johnny
Johnny Johnny johnny, johnny
Johnny Johnny johnny, johnny
Johnny B. Johnnyode

Fantastic, fantastic
Fantastic Johnny fantastic, fantastic
Fantastic Johnny fantastic, fantastic
Fantastic Johnny fantastic, fantastic
Fantastic Johnny fantastic, fantastic
Johnny B. Fantasticode

Edit: Thanks to weston for suggesting using a function

share|improve this answer
    
You don't need to provide a whole program, a function or better yet, lambda, will suffice. – weston yesterday
    
+1 Thanks for the ^32. That's shorter than the &~32 I was using. Also, a port of my Java 7 answer seems to be shorter: string x(string a){string x=(char)(a[0]^32)+a.Remove(0,1),n=a+"\n",c=", ",r=n+x+" Johnny "+a+c;return x+c+r+r+r+r+n+"Johnny B. "+x+"ode";}} (139 bytes) Try it here. – Kevin Cruijssen 16 hours ago
    
Hope you don't mind, but I've stole from you an idea. :P For not being known as a bad guy, I'll leave here a tip: You could convert your method into a lambda expression ( string x(string a) -> (a)=>, -13 bytes ), only 1 byte behind me ;) – auhmaan 15 hours ago
    
@auhmaan If you're compiling to a Func<string, string> you can just do a=> no need for the (). – TheLethalCoder 13 hours ago

MATLAB/Octave, 133 111 bytes

@(a)regexprep(['1, 2' 10 repmat(['1 32, 2' 10],1,4) '3B. 1ode'],{'1','2','3'},{[a(1)-32 a(2:end)],a,'Johnny '})

It's a start. Can hopefully be reduced further.

Basically it's an anonymous function which takes a string input and then uses regex to create the required output.

@(a)                                                    %Anonymous Function
    regexprep(                                          %Regex Replace
        ['1, 2' 10                                      %First line is: Code, code
            repmat(['1 32, 2' 10],1,4)                  %Then four lines of: Code Johnny code, code 
                               '3B. 1ode'],             %Final line: Johnny B. Codeode
         {'1','2','3'},                                 %1,2,3 are our replace strings in the lines above
         {[a(1)-32 a(2:end)],a,'Johnny '}               %We replace with '(I)nput', 'input' and 'Johnny ' respectively.
    )

An example:

@(a)regexprep(['1, 2' 10 repmat(['1 32, 2' 10],1,4) '3B. 1ode'],{'1','2','3'},{[a(1)-32 a(2:end)],a,'Johnny '});
ans('hi')
ans =

Hi, hi
Hi Johnny hi, hi
Hi Johnny hi, hi
Hi Johnny hi, hi
Hi Johnny hi, hi
Johnny B. Hiode

You can sort of Try it online!. The code doesn't quite work with Octave as all the upper case letters become ${upper($0)}, whereas in MATLAB this is converted to the actual upper case letter.

Given the input is guaranteed to only be a-z (lowercase alphabet), I can save 22 bytes by using a simple subtraction of 32 to convert the first letter in the string to capital, rather than using regex with the upper() function.

As a result, the code now works with Octave as well, so you can now Try it online!

share|improve this answer

Ruby, 89 88 86 79 bytes

My first golf submission :

->x{"^, *
#{"^ Johnny *, *
"*4}Johnny B. ^ode".gsub(?^,x.capitalize).gsub ?*,x}

Thanks a lot to @manatwork for his awesome comment : 7 bytes less!

share|improve this answer
1  
Nice. The parenthesis around the proc parameter are not needed; you can use literal newline characters instead of character escape; single letter string literals can be written with the ? notation; the parenthesis around the last .gsub's parameters are not needed. pastebin.com/6C6np5Df – manatwork yesterday
    
@manatwork: Wow, very impressive and nice of you. Thanks! – Eric Duminil yesterday

PHP, 88 Bytes

<?=$u=ucfirst($l=$argv[1]),", $l\n",$r="$u Johnny $l, $l\n","$r$r{$r}Johnny B. {$u}ode";
share|improve this answer

Stacked, 64 bytes

:@n tc@N('%N, %n
'!'%N Johnny %n, %n
'!4*'Johnny B. 'N'ode'!)sum

Try it online!

share|improve this answer

JavaScript, 98

s=>[S=s[0].toUpperCase()+s.slice(1),[,,,].fill(` ${s}
${S} Johnny `+s)]+`, ${s}
Johnny B. ${S}ode`

Abuses array-to-string serialization to create commas. Builds an array of the form:

["Go",
 " go\nGo Johnny go", (repeated...)]

And concatenates it to the string of the form ", go\nJohnny B. Goode":

["Go",
 " go\nGo Johnny go",
 " go\nGo Johnny go",
 " go\nGo Johnny go",
 " go\nGo Johnny go"] + ", go\nJohnny B. Goode"
share|improve this answer

Nova, 105 bytes

a(String s)=>"#{s.capitalize()+", #s\n"+"#s.capitalize() Johnny #s, #s\n"*4}Johnny B. #s.capitalize()ode"

Because Nova (http://nova-lang.org) is extremely early beta (and buggy), there are some obvious handicaps that are in place here keeping it from using even less bytes.

For example, could have saved capitalized function call (which is called 3 times) in a local variable like this:

a(String s)=>"#{(let c=s.capitalize())+", #s\n"+"#c Johnny #s, #s\n"*4}Johnny B. #{c}ode"

which would have taken the byte count down to 89 bytes. The reason this doesn't work now can be blamed on the argument evaluation order in the C language, because Nova is compiled to C. (The argument evaluation order will be fixed in a future update)

Even more, I could have introduced a "title" property in the String class (and I will after doing this lol) to reduce the count from the capitalization function call:

a(String s)=>"#{(let c=s.title)+", #s\n"+"#c Johnny #s, #s\n"*4}Johnny B. #{c}ode"

and that would free up 7 bytes to a new total of 82 bytes.

Furthermore (and further off), once lambda variable type inference is added, this would be valid:

s=>"#{(let c=s.title)+", #s\n"+"#c Johnny #s, #s\n"*4}Johnny B. #{c}ode"

The count could be brought down to 72 bytes.

By the way, this is my first code golf, so I probably have missed even more optimizations that could have been made. And this being a non-golf centric, general purpose language, I think it's pretty impressive.

The first 105 byte code works in the current Nova Beta v0.3.8 build available on http://nova-lang.org

class Test {
    static a(String s)=>"#{s.capitalize()+", #s\n"+"#s.capitalize() Johnny #s, #s\n"*4}Johnny B. #s.capitalize()ode"

    public static main(String[] args) {
        Console.log(a("expl"))
    }
}

outputs:

Expl, expl
Expl Johnny expl, expl
Expl Johnny expl, expl
Expl Johnny expl, expl
Expl Johnny expl, expl
Johnny B. Explode

Thank you for listening to my shameless advertisement for the general purpose language Nova (found at http://nova-lang.org ...get it now!!)

share|improve this answer

Java 7, 151 147 146 bytes

String c(String s){String x=(char)(s.charAt(0)^32)+s.substring(1),n=s+"\n",c=", ",r=n+x+" Johnny "+s+c;return x+c+r+r+r+r+n+"Johnny B. "+x+"ode";}

Explanation:

String c(String s){                           // Method with String parameter and String return-type
  String x=                                   //  Temp String with: 
           (char)(s.charAt(0)^32)             //   The first letter capitalized
    + s.substring(1),                         //   + the rest of the String
         n=s+"\n",                            //  Temp String with input + new-line
         c=", ",                              //  Temp String with ", "
         r=n+x+" Johnny "+s+c;                //  Temp String with "input\nInput Johnny input, "
  return x+c+r+r+r+r+n+"Johnny B. "+x+"ode";  //  Return output by putting together the temp Strings
}                                             // End of method

Test code:

Try it here.

class M{
  static String c(String s){String x=(char)(s.charAt(0)^32)+s.substring(1),n=s+"\n",j=" Johnny ",c=", ",r=n+x+j+s+c;return x+c+r+r+r+r+n+"Johnny B. "+x+"ode";}

  public static void main(String[] a){
    System.out.println(c("go"));
    System.out.println();
    System.out.println(c("code"));
    System.out.println();
    System.out.println(c("a"));
    System.out.println();
    System.out.println(c("johnny"));
    System.out.println();
    System.out.println(c("fantastic"));
  }
}

Output:

Go, go
Go Johnny go, go
Go Johnny go, go
Go Johnny go, go
Go Johnny go, go
Johnny B. Goode

Code, code
Code Johnny code, code
Code Johnny code, code
Code Johnny code, code
Code Johnny code, code
Johnny B. Codeode

A, a
A Johnny a, a
A Johnny a, a
A Johnny a, a
A Johnny a, a
Johnny B. Aode

Johnny, johnny
Johnny Johnny johnny, johnny
Johnny Johnny johnny, johnny
Johnny Johnny johnny, johnny
Johnny Johnny johnny, johnny
Johnny B. Johnnyode

Fantastic, fantastic
Fantastic Johnny fantastic, fantastic
Fantastic Johnny fantastic, fantastic
Fantastic Johnny fantastic, fantastic
Fantastic Johnny fantastic, fantastic
Johnny B. Fantasticode
share|improve this answer

CJam, 50 bytes

r:L(eu\+:M',SLN[MS"Johnny ":OL',SLN]4*O"B. "M"ode"

Try it online!

Explanation:

r:L(eu\+:M',SLN[MS"Johnny ":OL',SLN]4*O"B. "M"ode" e# Accepts an input token.
r:L                                                e# Gets input token and stores it in L.
   (eu\+:M                                         e# Converts token to uppercase-first and stores it in M.
          ',S                                      e# Appears as ", ".
             L                                     e# Input token.
              N                                    e# Newline.
               [                                   e# Opens array.
                M                                  e# Modified token.
                 S                                 e# Space.
                  "Johnny ":O                      e# Pushes "Johnny " and stores it in O.
                             L                     e# Input token.
                              ',SLN                e# The same {',SLN} as before.
                                   ]4*             e# Closes array and repeats it 4 times.
                                      O            e# "Johnny ".
                                       "B. "       e# "B. ".
                                            M      e# Modified token.
                                             "ode" e# "ode".
share|improve this answer

Pyke, 43 bytes

l5j", "Qs3
Qld"Johnny "iQs3:D4i"B. ode"+Tj:

Try it online!

Constructs and prints the first line then inserts Johnny go before the comma and duplicates that 4 times. Finally constructs the last part.

share|improve this answer
    
Doesn't seem to work for input johnny. tio.run/nexus/… – Dennis 2 days ago
    
I have no idea how I didn't spot that, fixed now – muddyfish 2 days ago

VBA, 138 Bytes

Subroutine that takes variant input b of assumed type string, and outputs by printing the the VBE immediates window

Sub a(b)
n=vbCr
c=b
Mid(c,1,1)=UCase(b)
s=c &", " &b
For i=1To 4
s=s &n &c &" Johnny " &b &", " &b
Next
Debug.?s &n &"Johnny B. " &c &"ode"
End Sub

Example Case

a "an"          ''  <- subroutine call
An, an          ''  <- output
An Johnny an, an
An Johnny an, an
An Johnny an, an
An Johnny an, an
Johnny B. Anode
share|improve this answer
    
Is Debug.?s effectively Debug.Print? How does that work? – BruceWayne yesterday
1  
@BruceWayne, nice cape. VBA is supports autoformatting, which means that things like ?,i=1To and &c are digested into more verbose but readable terms like Print, i = 1 To and & c. The community has decided that the compressed version of code in languages is acceptable for responses (see codegolf.meta.stackexchange.com/questions/10258/… ) – Taylor Scott 8 hours ago
1  
@BruceWayne As for ?, I believe it is a remnant from old version of Excel (4.0 and below) where Macro Sheets were used in place VBA via the VBE where it was used as a keyword for printing a string provided after it to a pre-indicated text file. The ? keyword itself is still very useful for code golfing as the Print keyword is used to write strings to a text file in current versions of VBA. Note, I am going off of memory with one so take that with a grain of salt. – Taylor Scott 8 hours ago
    
Good to know! I just asked, not for CodeGolf purposes, but because I'm constantly learning VBA and this was super new to me, so I was curious. Always like to learn neat little tricks in VBA. Cheers! – BruceWayne 8 hours ago

Kotlin, 112 Bytes

fun g(s:String):String{val u=s.capitalize();return "$u, $s\n${"$u Johnny $s, $s\n".repeat(4)}Johnny B. ${u}ode"}

Ungolfed:

fun g(s: String): String {
    val u = s.capitalize()
    return "$u, $s\n${"$u Johnny $s, $s\n".repeat(4)}Johnny B. ${u}ode"
}
share|improve this answer

Python, 258 bytes

from jinja2 import Template
def f(go):
    t = Template("""{{ Go }}, {{ go }}
{{ Go }} Johnny {{ go }}, {{ go }}
{{ Go }} Johnny {{ go }}, {{ go }}
{{ Go }} Johnny {{ go }}, {{ go }}
{{ Go }} Johnny {{ go }}, {{ go }}
Johnny B. {{ Go }}ode""")
    return t.render(Go=go.title(), go=go)
share|improve this answer
    
Notice this is exactly on par with Java at this moment, and it is sooo much readable ;) – user7610 2 days ago
1  
Welcome to the site! You could use string multiplication to shorten this answer. In addition it is not necessary to declare the variable t because it is only called once. – Wheat Wizard 2 days ago
    
Thanks, but I was aiming at exactly 258 bytes, to be on par with Java – user7610 2 days ago
2  
Why are you trying to match another score? This is code golf, not a readability contest. – weston 2 days ago
2  
@user7610 I think you're missing the point. – Mitch yesterday

Java 6, 258 242 bytes

enum j{;public static void main(String[]a){char[]b=a[0].toCharArray();b[0]^=32;System.out.printf("%1$s, %2$s\n%1$s %3$s%2$s, %2$s\n%1$s %3$s%2$s, %2$s\n%1$s %3$s%2$s, %2$s\n%1$s %3$s%2$s, %2$s\n%3$sB. %1$sode",new String(b),a[0],"Johnny ");}}

Longest part of it is the format for printf. There are problems with input different than string from a to z(yes I know I don't need to support anything else).

Ungolfed with comments:

enum j {
    ;

    public static void main(String[] a) {
        char[] b = a[0].toCharArray();              // Copy of the input string
        b[0]^=32;                                   // First character of copy to uppercase
        System.out.printf(
                "%1$s, %2$s\n%1$s %3$s%2$s, %2$s\n%1$s %3$s%2$s, %2$s\n%1$s %3$s%2$s, %2$s\n%1$s %3$s%2$s, %2$s\n%3$sB. %1$sode", // Format string
                new String(b),  // Capitalized string
                a[0],           // Original input string
                "Johnny ");     // "Johnny "
    }
}

EDIT: Golfed 16 bytes thanks to weston

share|improve this answer
1  
You can use a lambda to save lots of bytes. – corvus_192 2 days ago
1  
"Johnny" is always followed by a space. – weston 2 days ago
    
b[0]^=32; will also uppercase without the need for (char) cast. – weston 2 days ago

Pure Bash, 72 bytes (modified version of R. Kapp's answer):

M=hnny;echo -e ${1^}, $1 ${M//?/\\n${1^} Jo$M $1, $1}\\nJo$M B. ${1^}ode
share|improve this answer

Japt, 62 56 bytes

[1S]+U+R+`1 Johnny 0, 0
`²²+`Johnny B. 1o¸` d0U1Ug u +UÅ

Try it online!


62-byte solution using a substantially different technique:

Saved 3 bytes thanks to ETHproductions

W=Ug u +UÅ)+", {U}
"+`{W} Johnny {U}, {U}
`²²+`Johnny B. {W}o¸

Try it online!

share|improve this answer

C#, 159 130 bytes


Golfed

(i)=>string.Format("{0},{1}????\n{2} B. {0}ode".Replace("?","\n{0} {2}{1},{1}"),(i[0]+"").ToUpper()+i.Substring(1)," "+i,"Johnny");

Ungolfed

( i ) => string.Format( "{0},{1}????\n{2} B. {0}ode"
    .Replace( "?", "\n{0} {2}{1},{1}" ),

    ( i[ 0 ] + "" ).ToUpper() + i.Substring( 1 ), // {0}
    " " + i,                                      // {1}
    "Johnny" );                                   // {2}

Ungolfed readable

( i ) => string.Format( @"{0},{1}
    ????
    {2} B. {0}ode"

    // Replaces the '?' for the string format that contains the 
    // repetition of "___ Johnny ___, ___".
    .Replace( "?", "\n{0} {2}{1},{1}" ),

    // {0} - Converts the first letter to upper,
    //       then joins to the rest of the string minus the first letter
    ( i[ 0 ] + "" ).ToUpper() + i.Substring( 1 ),
    // {1} - The input padded with a space, to save some bytes
    " " + i,
    // {2} - The name used as parameter, to save some bytes
    "Johnny" );

Full code

using System;

namespace Namespace {
    class Program {
        static void Main( string[] args ) {
            Func<string, string> func = ( i ) =>
                string.Format( "{0},{1}????\n{2} B. {0}ode"
                    .Replace( "?", "\n{0} {2}{1},{1}" ),

                    ( i[ 0 ] + "" ).ToUpper() + i.Substring( 1 ),
                    " " + i,
                    "Johnny" );

            int index = 1;

            // Cycle through the args, skipping the first ( it's the path to the .exe )

            while( index < args.Length ) {
                Console.WriteLine( func( args[index++] ) );
            }

            Console.ReadLine();
        }
    }
}

Releases

  • v1.1 - -29 bytes - Thanks to Sir Bitesalot last update, who remembered me I could edit the string before format.
  • v1.0 - 159 bytes - Initial solution.

Notes

The title has a link to a page with the code and the test cases. Just hit Go and the result will be printed below the code.

share|improve this answer
    
No need for the () around the argument for the Func just do i=>. You can probably also make use of interpolated strings from C# 6 and lose the string.Format although I haven't looked at the code too much to see how (should be trivial). – TheLethalCoder 13 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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