57
14
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 awood
chuck chuck if awood
chuck could chuckwood
?
and the second word four times
- How much wood would a wood
chuck
chuck
if a woodchuck
couldchuck
wood?
with the rest of the output being the same for any inputs.
How much
woodwould a
woodchuckchuck
if a
woodchuckcould
chuckwood
?
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 code-golf, 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....)
2May we assume the two words will be two distinct words? – Jonathan Allan – 2019-08-19T18:12:13.050
4...I guess
"", ""
means no :p – Jonathan Allan – 2019-08-19T18:25:55.847@dzaima Edited to clarify. I don't want the input character set to be the main focus, so I'll trust golfers for the most part. – Greg Martin – 2019-08-19T19:30:07.727
IMHO I think a) the phrase doesn't make sense with "could", since maybe it wouldn't anyway b) you really need the homophone. – Neil – 2019-08-19T19:49:02.200
How reasonable is "reasonable"? – Khuldraeseth na'Barya – 2019-08-19T21:17:09.027
Is input allowed to be taken in reverse order: e.g.
'chuck' 'wood'
? – maxb – 2019-08-20T09:27:51.947I am mildly disappointed that none of the test cases were
"ground", "hog"
(since "woodchuck" is another name for a "groundhog"...) – Chronocidal – 2019-08-20T11:10:54.2371@Chronocidal I can't stand to see you disappointed.... – Greg Martin – 2019-08-20T16:33:37.807
@maxb I guess I don't see any reason to disallow the "wrong" order for inputs ... a tiny bit confusing maybe, but just saying so in the answer seems like enough to me. – Greg Martin – 2019-08-20T16:35:01.150
6Two. It would golf two code. – user2357112 supports Monica – 2019-08-20T20:31:19.770
2Aw, I was hoping this would be about a short program that can do some simple golfing transformation(s) on other code. – aschepler – 2019-08-20T23:48:52.943
1I am going to have the "jabber", "wock" one stuck in my head, now. – David Conrad – 2019-08-21T16:00:01.680
It doesn't quite fit the pattern, but I'm fond of "How many dice would a dyed die dye if a dyed die could dye dice?" – Nathan – 2019-08-22T03:54:31.283
1Shouldn't the invariant space between "chuck" and "wood" in the example's third form also be
code-quoted
? – Leif Willerts – 2019-08-22T19:20:01.730"How much would a would a would ahow much how much if a would ahow much could how much would a?" - ROFL – Thomas Weller – 2019-08-22T22:47:18.007