74
\$\begingroup\$

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
\$\endgroup\$
8
  • 46
    \$\begingroup\$ Missed opportunities for test cases: an, c, cath \$\endgroup\$
    – Neil
    Mar 19, 2017 at 10:08
  • 54
    \$\begingroup\$ Somebody please do a Go version. \$\endgroup\$
    – jl6
    Mar 19, 2017 at 10:59
  • 2
    \$\begingroup\$ How should the program handle multi-word strings? \$\endgroup\$
    – sporkl
    Mar 19, 2017 at 17:54
  • 6
    \$\begingroup\$ Let's just observe a minute or two of silence, and wish Rest In Peace to Chuck. \$\endgroup\$ Mar 19, 2017 at 19:51
  • 1
    \$\begingroup\$ The code text sounds best when spoken by Google Translator in Spanish: translate.google.com/#es/en/… \$\endgroup\$
    – palsch
    Mar 22, 2017 at 18:33

45 Answers 45

1
2
1
\$\begingroup\$

Japt, 62 53 bytes

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

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!

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

Swift, 151 144 bytes

import Foundation
func b(a:String){let u=a.capitalized;print(u+", "+a);for _ in 0..<4{print(u+" Johnny "+a+", "+a)};print("Johnny B. "+u+"ode")}


Previous Version:

import Foundation
func b(s:String){let u=s.capitalized;print("\(u), \(s)");for _ in 0..<4{print("\(u) Johnny \(s), \(s)")};print("Johnny B. \(u)ode");}


Ungolfed:

import Foundation
func beGoode(inputString: String) {
        let capitalizedString = inputString.capitalized
        print("\(capitalizedString), \(inputString)")
        for _ in 0..<4 {
            print("\(capitalizedString) Johnny \(inputString), \(inputString)")
        }
        print("Johnny B. \(capitalizedString)ode")
    }

Example:

b(s: "code")

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

Edit: Golfed down 6 bytes by using string concatenation instead of interpolation. Down 1 byte more by removing final semi-colon.

\$\endgroup\$
2
  • \$\begingroup\$ Welcome to the site! \$\endgroup\$
    – DJMcMayhem
    Mar 23, 2017 at 14:48
  • \$\begingroup\$ Thanks! I thought I'd finally try my hand at a solution. \$\endgroup\$
    – Stephen
    Mar 23, 2017 at 14:56
1
\$\begingroup\$

Kotlin, 112, 99 Bytes

fun g(s:String)=s.capitalize().let{"$it, $s\n${"$it Johnny $s, $s\n".repeat(4)}Johnny B. ${it}ode"}

Ungolfed:

fun g(s: String) = s
        .capitalize()
        .let {
            "$it, $s\n${"$it Johnny $s, $s\n".repeat(4)}Johnny B. ${it}ode"
        }
\$\endgroup\$
1
\$\begingroup\$

PHP, 84 83 bytes

Good Bye, Chuck!

<?=strtr(str_pad("1, 0",41,"
1 2 0, 0")."2 B. 1ode",[$argn,ucfirst($argn),Johnny]);

or

<?=strtr(str_pad("1,0",32,"
1 20,0")."2 B. 1ode",[" $argn",ucfirst($argn),Johnny]);

Run with echo '<input>' | php -nF <filename> or try them online.

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

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

Try it online!

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

Q, 97 bytes

{u:(upper x[0]),1_x;u,", ",x,"\n",((,/)4#enlist u," Johnny ",x,", ",x,"\n"),"Johnny B. ",u,"ode"}

Assuming input "go".

  1. Defines uppercase input as variable u.
  2. Merges u with input x to generate first line, "Go, go".
  3. Copies body, "Go Johnny go, go", four times.
  4. Merges with final line, "Johnny B. Goode".
\$\endgroup\$
0
\$\begingroup\$

Common Lisp, 107 bytes

(apply'format t"~:(~A~), ~a~%~4@{~:(~A~) Johnny ~a, ~a ~%~}Johnny G. ~:(~A~)ode"(fill(make-list 15)(read)))

Try it online!

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

Japt, 52 bytes

[V=UhUg u)',SUR[VSW="Johnny "U',SUR]¬²²W`B. {V}o¸`]¬

Try it

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

C (gcc), 110 bytes

n;f(char*s){for(n=6;n--;)printf(n?n^5?"%c%s Johnny %s, %s\n":"%c%s, %s\n":"Johnny B. %c%sode",*s-32,s+1,s,s);}

Try it online!

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

Excel, 103 bytes

-8 bytes saved by using # and ~ instead of Go and go

=SUBSTITUTE(SUBSTITUTE("#, ~
"&REPT("# Johnny ~, ~
",4)&"Johnny B. #ode","#",PROPER(A1)),"~",LOWER(A1))
\$\endgroup\$
0
\$\begingroup\$

SOGL V0.12, 38 bytes

,1Ƨ, Ο,@+"9:█ŗ‘⁽:A+⁴+:³a,⁽"B. ŗode”+⁰⁽

Try it Here!

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

Pyth, 69 67 bytes

.F++"{0}, {1}\n"*"{0} {2} {1}, {1}\n"4"{2} B. {0}ode"[rz4rz0"Johnny

Try it here!

Python 3 translation:
z=input()
print(("{0}, {1}\n"+"{0} {2} {1}, {1}\n"*4+"{2} B. {0}ode").format(z.capitalize(),z.lower(),"Johnny"))
\$\endgroup\$
0
\$\begingroup\$

Stax, 34 bytes

₧:hç╟╫9↓Σl(ܰ╤`╨+B╥¢└ÇI╩4╢YP-├Γ■fl

Run and debug it

Unpacked, ungolfed, and commnted, it looks like this.

:.X         title case input and store in x register        e.g. "Code"
., +        concat ", "                                     e.g. "Code, "
y+Q         concat input and print without popping          e.g. "Code, code"
x`?*u)U"`+  concat " Johnny " to x                          e.g. "Code, code" "Code Johnny "
sv+         swap top of stack, lowercase, concat            e.g. "Code Johnny code, code"
QQQQ        print 4 times without popping                   e.g. "Code Johnny code, code"
j1@p        split, print the second word without newline    e.g. "Johnny"
" B. `xode  output string template with x register embedded e.g. " B. Codeode"

Run this one

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

Jstx, 52 bytes

₧&Eu◄, :;4♦/u♂ Johnny♀:◄, :;► :;41u☼◘~ΘåÆëë╟┌°;♫☺åΘ:

Try it online!

Explanation

₧&          # Push literal 100
E           # Push the second stack value the absolute value of the first stack value times.
u           # Push the first stack value transformed to Title Case.
◄,          # Push literal , 
:           # Push the sum of the second and first stack values.
;           # Push the difference of the second and first stack values.
4           # Print the first stack value, then a newline.
♦           # Push literal 4
/           # Enter an iteration block over the first stack value.
u           # Push the first stack value transformed to Title Case.
♂ Johnny♀   # Push literal  Johnny
:           # Push the sum of the second and first stack values.
◄,          # Push literal , 
:           # Push the sum of the second and first stack values.
;           # Push the difference of the second and first stack values.
►           # Push literal  
:           # Push the sum of the second and first stack values.
;           # Push the difference of the second and first stack values.
4           # Print the first stack value, then a newline.
1           # End an iteration block.
u           # Push the first stack value transformed to Title Case.
☼◘~ΘåÆëë╟┌° # Push literal Johnny B. 
;           # Push the difference of the second and first stack values.
♫☺åΘ        # Push literal ode
:           # Push the sum of the second and first stack values.
\$\endgroup\$
0
\$\begingroup\$

Python 2, 156 bytes

#coding:UTF-8
import sys;a="þ, ÿ"+("\nþ Johnny ÿ, ÿ"*4)+"\nJohnny B. þode";print a.replace("þ",sys.argv[1].title()).replace("ÿ",sys.argv[1].lower())

De-golfed:

#coding:UTF-8
import sys
a = "þ, ÿ" + ("\nþ Johnny ÿ, ÿ" * 4) + "\nJohnny B. þode"
b = a.replace("þ", sys.argv[1].title())
c = b.replace("ÿ", sys.argv[1].lower())
print c

Works as long as input doesn't contain the character ÿ, but passes all test cases.

Bytes counted by this byte counter.

\$\endgroup\$
1
1
2

Your Answer

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

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