83
14
My dog is called Rex. Every time I scold him, he seems not very impressed and the only times I see him react is when I pronounce his name. If I say
Rex, I told you not to do this! You're making me angry Rex!
all he hears is
Rex, * **** *** *** ** ** ****! ***'** ****** ** ***** Rex!
The challenge : given an input string, your program must output the same string where all alphabetic characters have been turned to stars, except the characters in the appearances of the word Rex
, who must be left untouched. The non-alphabetic characters are also left untouched.
Details : The challenge is case-insensitive, thus rex
must be left untouched also. The word Rex
can be part of another word, so for example anorexic
must be rendered as ***rex**
.
Update : as the initial text of this challenge did not clarify how underscores or numbers or accentuated characters should be treated, I do not make any special requirement on those characters. Thus, a solution is valid as long as characters in a-zA-Z
(and also the one mentioned in the examples, ,!".
) are handled correctly.
Test cases :
Input : Rex lives in Rexland.
Output : Rex ***** ** Rex****.
Input : To call Rex, just say "Rex".
Output : ** **** Rex, **** *** "Rex".
Input : My cat is getting anorexic.
Output : ** *** ** ******* ***rex**.
Will the string contain newlines? – Neil – 2017-05-09T09:12:08.587
27Test case:
Hello! Isn't this ... a nice challenge?
Can you dog hear*****! ***'* *** ... * **** *********?
? If so, you might consider communicating in morse from now on... – Stewie Griffin – 2017-05-09T09:16:17.1732Do we only need to support
a-zA-Z
, or also0-9
and/oräëïöüÿãõñáéíóúýàèìòùç
etc. etc.? And could you add some test cases regarding these? – Kevin Cruijssen – 2017-05-09T09:20:41.3202@KevinCruijssen Since $0-9$ or accented characters are not mentioned in the initial challenge, do not consider them as part of the challenge. – Ewan Delanoy – 2017-05-09T09:23:29.447
@Shaggy I think we can assume standard ASCII, but replace digits or not is a good question. – Titus – 2017-05-09T10:47:45.713
@Shaggy The non-alphabetic characters are also left untouched. Alphabetic characters don't include digits. – 2501 – 2017-05-09T10:55:50.767
Can I have an additional new line character at the end? – Christoph – 2017-05-09T10:57:41.153
Will there be newlines in the middle of the string? – Mego – 2017-05-09T11:30:21.950
7
Since "dogs don't get the difference between lowercase and uppercase", may the output case be different to the input? (For example: input=
– Jonathan Allan – 2017-05-09T16:02:44.450"Rex lives in Rexland."
, output="rex ***** ** rex****."
; or alternatively input="My cat is getting anorexic."
, output="** *** ** ******* ***Rex**."
)I once had a dog that could spell. – Joshua – 2017-05-10T18:07:27.967
@Joshua Really ? – Ewan Delanoy – 2017-05-10T18:12:12.810
@EwanDelanoy: Yeah really. We're pretty sure it came from spelling words we didn't want him to overhear. Near the end we were pretty sure he could spell any word he knew, which was quite a few. – Joshua – 2017-05-10T18:14:17.477
1Does Rex not respond to [Dog park, walk, treat]? When my dog was shaking I made a joke about him having "Dog parkinsons" and he definitely only heard "Dog park******" – Nic Robertson – 2017-05-10T21:36:02.907
@Adám Indeed. Sorry for the mistake, I just corrected it – Ewan Delanoy – 2017-05-11T09:22:36.680
@EwanDelanoy You may want to wait more than two days before accepting an answer, for two reasons: Challenges with no accepted submission may be less attractive, and you are likely to have to reaccept (which could cause bad feelings). I generally wait a week or so, except if there is a 0-2 byte solution. – Adám – 2017-05-11T09:25:25.070
@Adám Thanks you for your advice. I don't have much experience for participating in this forum. At least my motives for reaccepting are crystal clear (number of bytes). – Ewan Delanoy – 2017-05-11T09:35:24.970
Ewan, we still need an answer to @Adám's question about underscores.
– Shaggy – 2017-05-11T12:07:56.047@Adám Yes, I wasn't sure about the best way to fix the challenge and had forgotten about my earlier comment. Hope it's all OK now – Ewan Delanoy – 2017-05-11T13:31:57.623
@EwanDelanoy Yes, thank you. – Adám – 2017-05-11T13:35:46.707
Thanks, @Adám & Ewan; that saves me 3 bytes :)
– Shaggy – 2017-05-11T13:55:52.1875
Why did this challenge use asterisks instead of "blah"s???
– hBy2Py – 2017-05-11T19:44:53.5171
Idea possibly from Far Side.
– imallett – 2017-05-13T06:49:15.763This answer is shorter than my accepted one. – Adám – 2017-06-27T02:25:22.617
My new answer is shorter than the newly accepted one. – Adám – 2017-06-27T09:16:53.240