You are providing tech support to the Bruce Dickenson as he produces a Blue Öyster Cult recording session. When he asks for more cowbell, you can give it to him.
Your task
Write a program or function that takes a string (or equivalent in your language) as input, and outputs a related string containing one more cowbell.
How many cowbells does a string contain?
The number of cowbells a string contains equals the maximum number of distinct copies of "cowbell" that can be obtained by permuting the characters of the string. For example, "bbbccceeellllllooowwwwwwwww"
contains 3 cowbells, while "bbccceeellllllooowwwwwwwww"
and "bbbccceeelllllooowwwwwwwww"
each contain 2 cowbells, and "cowbel"
contains 0 cowbells.
How should the output be related to the input?
The output should consist of the concatenation, in this order, of the input string and the shortest prefix of the input string needed to increase the number of cowbells.
For example, "bbbccceeelllllooowwwwwwwww"
only needs one additional "l"
to contain 3 cowbells instead of 2; the shortest prefix that contains that "l"
is "bbbccceeel"
. Therefore, if the input is "bbbccceeelllllooowwwwwwwww"
, then the output should be "bbbccceeelllllooowwwwwwwwwbbbccceeel"
.
Technicalities
- You may assume that the input contains only printable ASCII characters. If there are one or two characters that are annoying for your language's string processing (such as newlines or
\
), you can assume that the input doesn't contain them—just mention this restriction. - You may further assume that the alphabetic characters in the input are all lowercase, or all uppercase. If you choose not to assume one of these, count cowbells case-insensitively.
- You may further assume that the input contains at least one copy of each of the characters
b
,c
,e
,l
,o
, andw
. This is equivalent to assuming that some prefix of the string can be concatenated to it to produce a string that contains more cowbell. (Note that the input string itself need not contain a cowbell.) - If your language has a builtin that solves this problem ... then totally use it, seriously, how awesome is that.
Gold-plated diapers
Since recording studio time is expensive, your code must be as short as possible. The entry with the fewest bytes is the winner!
Test cases
(pastebin link for easier copy/pasting)
Test input #1: "christopher walken begs for more cowbell!"
Test output #1: "christopher walken begs for more cowbell!christopher wal"
Test input #2: "the quick brown fox jumps over the lazy dog"
Test output #2: "the quick brown fox jumps over the lazy dogthe quick brown fox jumps over the l"
Test input #3: "cowbell"
Test output #3: "cowbellcowbell"
Test input #4: "cowbell cowbell cowbell"
Test output #4: "cowbell cowbell cowbellcowbell"
Test input #5: "cowbell cowbell cowbel"
Test output #5: "cowbell cowbell cowbelcowbel"
Test input #6: "bcelow"
Test output #6: "bcelowbcel"
Test input #7: "abcdefghijklmnopqrstuvwxyz"
Test output #7: "abcdefghijklmnopqrstuvwxyzabcdefghijkl"
Test input #8: "cccowwwwbbeeeeelllll"
Test output #8: "cccowwwwbbeeeeelllllccco"
Test input #9: "be well, programming puzzles & code golf"
Test output #9: "be well, programming puzzles & code golfbe well, programming puzzles & c"
Test input #10: "lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. wow!"
Test output #10: "lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. wow!lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut lab"
Test input #11:
"c-c-b-c
i have a cow, i have a bell.
uh! bell-cow!
i have a cow, i have a cowbell.
uh! cowbell-cow!
bell-cow, cowbell-cow.
uh! cow-cowbell-bell-cow.
cow-cowbell-bell-cow!
"
Test output #11:
"c-c-b-c
i have a cow, i have a bell.
uh! bell-cow!
i have a cow, i have a cowbell.
uh! cowbell-cow!
bell-cow, cowbell-cow.
uh! cow-cowbell-bell-cow.
cow-cowbell-bell-cow!
c-c-b-c
i have a cow, i have a bell"
test case -> result
in one large preformatted code block. It's much nicer aesthetically and easier to copy paste. \$\endgroup\$L
s in the word, this is not what the challenge asks. \$\endgroup\$