Introduction:
Inspired by the Puzzling-stackexchange post with the same name, which I've answered four years ago:
Can you create a perfectly valid English sentence, which makes perfect sense, but which contains the word "and" in it, five times consecutively in a row ?
"Something-or-other and and and and and something-else."
Let's say we have a store owner and his clerk. The store owner want the clerk to make a sign for the shop, which has the name (for example): "Toys And Puzzles".
So, the clerk makes the sign and presents it to the owner.
The owner thinks the spacing isn't really good. It currently looks something like:
Toys And Puzzles
but he wanted it to look more like:
Toys And Puzzles
So he says to the clerk:
"The spacing between Toys and And and And and Puzzles should be a bit larger. Could you please fix that?"
Challenge:
Given a string input, replace all occurrences of the word 'and' with five times that word; three in lowercase, interleaved with two of the original cased word.
Some examples:
AND
would becomeand AND and AND and
and
would becomeand and and and and
AnD
would becomeand AnD and AnD and
There is one catch however (restricted-source):
You're not allowed to use the characters aAnNdD
in your source code. Any other character is still allowed, even if it's the unicode value of these letters, only these six characters themselves are banned.
Challenge rules:
- Your source code cannot contain any of the characters
aAnNdD
. - You can assume the input-string only contains spaces and letters (both lower- and uppercase)
- You can assume the input is non-empty
- It is possible that the input-string does not contain the word 'and', in which case it's returned as is
- Instead of a string you are also allowed to take the input as a list/array/stream of characters/code-point-integer (or other similar variations)
- Don't replace substrings of
and
if it isn't a standalone word (see test cases withstand
,band
, andAnderson
)
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language. - Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
Test cases:
Input: "Toys And Puzzles"
Output: "Toys and And and And and Puzzles"
Input: "and"
Output: "and and and and and"
Input: "AND and anD"
Output: "and AND and AND and and and and and and and anD and anD and"
Input: "Please stand over there and watch" # note that the "and" in "stand" isn't changed
Output: "Please stand over there and and and and and watch"
Input: "The crowd loves this band" # note that the "and" in "band" isn't changed
Output: "The crowd loves this band"
Input: "Toys and And and And and Puzzles"
Output: "Toys and and and and and and And and And and and and and and and and And and And and and and and and and Puzzles"
Input: "Mr Anderson went for a walk and found a five dollar bill" # note that the "And" in "Anderson" isn't changed
Output: "Mr Anderson went for a walk and and and and and found a five dollar bill"
andAND
letters in code means a lot of language constructs just aren't allowed, making a regex-based method even more tempting. And Python can'tprint
,return
, orlambda
, and so needs some imagination to even output anything. \$\endgroup\$(?i)\band\b
withand $0 and $0 and
for language with regex, and felt it needed something enforcing people to be a bit more creative with their answers, hence the restricted-source. I also realize this is just a flaw in my base challenge, since do-X-without-Y challenges are usually discouraged, but I felt without it the challenge would be too boring. Out of curiosity: what would you have changed to still have the base challenge, but without only seeing the to-the-point regex-replace approach? \$\endgroup\$