# How much code would a codegolf golf if a codegolf could golf code?

Write a function or program that takes two words as input and outputs variants of the popular English tongue-twister "How much wood would a woodchuck chuck if a woodchuck could chuck wood?".

The output will use the first word four times

• How much wood would a woodchuck chuck if a woodchuck could chuck wood?

and the second word four times

• How much wood would a woodchuck chuck if a woodchuck could chuck wood?

with the rest of the output being the same for any inputs.

• How muchwoodwould awoodchuckchuckif awoodchuckcouldchuckwood?

The input and output can be in any format that your language reasonably recognizes as dealing with strings of text. The output must be exactly in the indicated format, including capitalization, spaces and lack thereof, and the ending question mark. An optional trailing newline is acceptable.

Ideally your code will handle input containing any printable ASCII characters. However, it is permitted to restrict the input to reasonable subsets of printable ASCII; just indicate this in your answer. Handling larger character sets is of course fine.

Example input-output pairs:

"wood", "chuck"
"How much wood would a woodchuck chuck if a woodchuck could chuck wood?"

"ground", "hog"
"How much ground would a groundhog hog if a groundhog could hog ground?"

"bar", "keep"
"How much bar would a barkeep keep if a barkeep could keep bar?"

"money", "belt"
"How much money would a moneybelt belt if a moneybelt could belt money?"

"rain", "fall"
"How much rain would a rainfall fall if a rainfall could fall rain?"

"hair", "cut"
"How much hair would a haircut cut if a haircut could cut hair?"

"green", "house"
"How much green would a greenhouse house if a greenhouse could house green?"

"jabber", "wock"
"How much jabber would a jabberwock wock if a jabberwock could wock jabber?"

"pine", "apple"
"How much pine would a pineapple apple if a pineapple could apple pine?"

"Rob", "Lowe"
"How much Rob would a RobLowe Lowe if a RobLowe could Lowe Rob?"

"code", "golf"
"How much code would a codegolf golf if a codegolf could golf code?"

"fish", ""
"How much fish would a fish  if a fish could  fish?"

"", "fish"
"How much  would a fish fish if a fish could fish ?"

"", ""
"How much  would a   if a  could  ?"

"  ", "     "
"How much    would a               if a         could         ?"

"would a", "how much"
"How much would a would a would ahow much how much if a would ahow much could how much would a?"


This is , so fewest bytes wins. Answers are welcome in all languages, even if some other language can do it in fewer bytes.

(Inspired by this meme, which uses one input pair better than this rigid pattern does....)

• May we assume the two words will be two distinct words? – Jonathan Allan Aug 19 '19 at 18:12
• ...I guess "", "" means no :p – Jonathan Allan Aug 19 '19 at 18:25
• @Chronocidal I can't stand to see you disappointed.... – Greg Martin Aug 20 '19 at 16:33
• Two. It would golf two code. – user2357112 supports Monica Aug 20 '19 at 20:31
• Aw, I was hoping this would be about a short program that can do some simple golfing transformation(s) on other code. – aschepler Aug 20 '19 at 23:48

# Bash, 58 bytes

echo "How much $1 could a$1$2$2 if a $1$2 could $2$1?"


Takes input as command line arguments. Try it online!

# Batch, 56 bytes

@echo How much %1 would a %1%2 %2 if a %1%2 could %2 %1?


# Python 3, 67 bytes

'How much {0} would a {0}{1} {1} if a {0}{1} could {1} {0}?'.format


Try it online!

Point-free Python

• Welcome to the site! I'd recommend you add a link to an online interpreter (like Try it online!), so that others can verify your program! – caird coinheringaahing Aug 21 '19 at 15:33
• Thanks for the suggestion/link @cairdcoinheringaahing. I added the link, and I'll spend some time to familiarize myself with TIO. – Will Da Silva Aug 21 '19 at 15:52

# Perl 5, 56 bytes

/ /;$_="How much$' would a $'$ $ if a$'$ could$_?"


Try it online!

<?=strtr('How much 1 would a 12 2 if a 12 could 2 1?',$argv);  Try it online! Taking advantage of PHP's strtr array replacement mode. In strtr, when second parameter is an array, it replaces array keys with the corresponding value for that key. PHP's $argv index/key 0 is always filled by PHP and starting from index 1, command line arguments are put in it. So I pass the two words as command arguments which will be placed at index 1 and 2 in $argv and then the 1s and 2s in the string will be replaced by those values. # PHP (7.4), 62 bytes fn($a)=>strtr('How much 0 would a 01 1 if a 01 could 1 0?',$a)  Try it online! # PHP (7.4), 63 bytes fn($a,$b)=>"How much$a would a $a$b $b if a$a$b could$b $a?"  Try it online! # Canvas, 4240 39 bytes ；⁸⁸⁷⁷“UＮｑＯ1Uŗ７_ＷW７eV↷:７⁹3ｕ5G!oａ⁷⁴ｄ：⌐Ｑ‟  Try it here! Canvas's compression unfortunately currently doesn't have an English dictionary mode as I'm lazy. # Ruby, 69 71 bytes ->a,b{"How much #{a} would a #{a+b} #{b} if a #{a+b} could #{b} #{a}?"}  Try it online! • I'm afraid you misread the challenge. The 1st modal verb is “would”. – manatwork Aug 19 '19 at 20:20 • Noooooo my beautiful byte saves... – Value Ink Aug 20 '19 at 0:07 # Red, 77 bytes func[a b][rejoin["How much "a" would a "a b" "b" if a "a b" could "b" "a"?"]]  Try it online! # Pyth, 49 bytes AQjd["How much"G"would a"J+GHH"if a"J"could"H+G\?  Try it online! AQ: Take the two-element list Q (input) and assign the first element to G, the second to H jd: join on d (=" ") the following list [: starts list definition, ends implicitly with the end of the program. All following values are elements of the list J+GH: concatenate G and H so it won't be joined with a space between, save it to J \?: One-character string consisting of "?"  # Excel, 79 bytes =SUBSTITUTE(SUBSTITUTE("How much 0 would a 01 1 if a 01 could 1 0?",0,A1),1,A2)  Simple substitution. First string cannot contain 1. • As it turns out, this is the same length as the more straightforward approach which has no restrictions on input: ="How much "&A1&" would a "&A1&A2&" "&A2&" if a "&A1&A2&" could "&A2&" "&A1&"?" – Engineer Toast Aug 20 '19 at 12:07 • Not if you use named ranges A and B. ="How much "&A&" would a "&A&B&" "&B&" if a "&A&B&" could "&B&" "&A&"?" – user3819867 Aug 20 '19 at 13:36 • @user3819867, would that not be ="How much "&A:A&" would a "&A:A&B:B&" "&B:B&" if a "&A:A&B:B&" could "&B:B&" "&A:A&"?" – Wernisch Aug 20 '19 at 14:03 • Named range, you can define the name in names manager (Ctrl+F3). You can enter any non-reserved string, including 1 char length. – user3819867 Aug 21 '19 at 9:04 • Have toyed with named ranges before. Don;t think its in the spirit of CodeGolf. Do we add bytecount for the naming? – Wernisch Aug 21 '19 at 9:16 # Dart, 61 bytes f(a,b)=>"How much$a would a $a$b $b if a$a$b could$b $a?";  Try it online! # Scala, 74 bytes (a:String,b:String)=>s"How much$a would a $a$b $b if a$a$b could$b $a?"  Try it online! # MathGolf, 40 bytes ▌_l@lll╩Bßx¬╩5╩♦Γ╫¬╩-╩♦?ß¬╩à╩e?ß¬]─ uδ'?  Try it online! Probably suboptimal. Relies on manipulating the stack, and generating the sentence starting from the end. I might write an explanation if someone really wants it, nothing magic is happening. # Java (JDK), 76 bytes a->b->"How much "+a+" would a "+a+b+" "+b+" if a "+a+b+" could "+b+" "+a+"?"  Try it online! # Emacs Lips, 79 bytes (lambda(a b)(concat"How much "a" would a "a b" "b" if a "a b" could "b" "a"?"))  # Perl 5-pa, 61 bytes $_="How much 0 would a 01 1 if a 01 could 1 0?";s/\d/$F[$&]/g


Try it online!

# Julia 1.0, 56 bytes

a/b="How much $a would a$a$b$b if a $a$b could $b$a?"


Try it online!

# Python 2, Python 3 - 78 bytes

lambda a,b:' '.join(('How much',a,'would a',a+b,b,'if a',a+b,'could',b,a))+'?'


Try it online!

no format strings, a tad shorter than @Tryer 's format

# V (vim), 46 bytes

iHow much ò would a aò b if a òò could b ò?


Try it online!

Hexdump:

00000000: 6948 6f77 206d 7563 6820 f220 776f 756c  iHow much . woul
00000010: 6420 6120 1261 f220 1262 2069 6620 6120  d a .a. .b if a
00000020: f2f2 2063 6f75 6c64 2012 6220 f23f       .. could .b .?


# AWK, 64 bytes

$0="How much "$1" could a "$1$2" "$2" if a "$1$2" could "$2" "\$1


Try it online!

I tried being clever with string substitutions and/or print statements, but I couldn't make it shorter.

# SAP ABAP, 95 bytes

FORM f USING a b.WRITE:'How much',a,'would a',a && b,b,'if a',a && b,'could',b,a &&'?'.ENDFORM.


Input should be of type string to preserve spaces/not add any extra ones. Example program:

REPORT z.
PARAMETERS:
a TYPE string LOWER CASE,
b TYPE string LOWER CASE.
PERFORM f using a b.


Rather boring code, not much to golf. Removing spaces where they are not needed. String concatenation using a && b is obviously shorter than doing a NO-GAP,b.

While modern ABAP can do string interpolation (WRITE:|{ a } { b }|.), it doesn't save a single byte, because as per usual there are too many mandatory spaces. The boring alternative (WRITE:a,b.) even implicitly appends a space to the output after each ,, making the choice an easy one...

For comparison:
WRITE:|How much { a } would a { a }{ b } { b } etc...|.
WRITE:'How much',a,'would a',a && b,b,'etc...'

• I could lose 10 bytes here if it's legal to use the variables defined in the surrounding program (this allows me to remove USING a b). But then my subroutine depends on the correct naming of these two variables in the calling program, which leads me to believe that it's probably not allowed. – Maz Aug 22 '19 at 8:24

# Clojure, 102 bytes

(#(println"How much"%1"would a"(str %1%2)%2"if a"(str %1%2)"could"%2(str %1\?))(read-line)(read-line))


Try it online!