Because rickrolling is the greatest meme on Earth, you [know the rules and so do I] are to write the shortest code that can textually rickroll the unsuspecting reader. Let [you down] there be an input text which contains letters, punctuation, and spaces. Anytime a [lie and hurt you] phrase from the first two stanzas appears in the text...
We're no strangers to love
You know the rules and so do I
A full commitment's what I'm thinking of
You wouldn't get this from any other guy
I just wanna tell you how I'm feeling
Gotta make you understand
Never gonna give you up
Never gonna let you down
Never gonna run around and desert you
Never gonna make you cry
Never gonna say goodbye
Never gonna tell a lie and hurt you
...insert the rest of the line in brackets afterwards.
Input
Input is a single line string containing only printable ASCII with optional trailing newline.
Output
Output is a single-line string. Any time that a group of words (defined as the input string split on spaces) matches a group of words in lines of the lyrics above, insert the remaining words of the line into the string, grouped in square brackets.
Additional Description:
This is code-golf, fewest bytes wins. You may write a program or function.
- matching should be case insensitive:
we're
is converted towe're [no strangers to love]
even thoughWe're
is capitalized in the lyrics. - matching should be greedy.
Does he know the answer?
should be converted toDoes he know the [rules and so do I] answer?
instead ofDoes he know [the rules and so do I] the [rules and so do I] answer?
- If a word appears more than once in the provided lyrics, choose any of the occurrences to complete the line.
- If a word is the last word in the lyric line, don't insert anything after it.
- Punctuation is included as part of a "word."
I'm
is a single word and cannot match withI
. Similarly,you.
doesn't match with any lyrics because of the period.
Some words like I
appear multiple times throughout the lyrics as well as at the end of a line. Since the rule is that any occurrence in the above lyrics can be used, and one of those occurrences is at the end of a line, no matching of I
is necessary. The other option for I
is [just wanna tell you how I'm feeling]
.
If two matches overlap, you may choose either one. This means that how I'm thinking
could become how I'm [feeling] thinking [of]
OR how [I'm feeling] I'm thinking [of]
since the I'm
could be part of either how I'm
or I'm thinking
. If, however the input text was simply I'm thinking
, then the output should be I'm thinking [of]
.
Additional test cases:
I don't know what I'm doing with my life.
is converted to
I [just wanna tell you how I'm feeling] don't know [the rules and so do I] what I'm [thinking of] doing with my life.
Many additional solutions are possible, since words like `I` appear multiple times.
Will someone please save me from these memes?
is converted to
Will someone please save me from [any other guy] these memes?
Two strangers walked into a bar. One said "hello." The other said "goodbye."
is converted to
Two strangers [to love] walked into a [lie and hurt you] bar. One said "hello." The [rules and so do I] other [guy] said "goodbye."
Challenge inspired by this dude.
from
should becomefrom [any other guy]
). \$\endgroup\$