17
1
I use "suffix" loosely here to mean "any sub-string that follows the prefix".
"Prefix" here means the START of a word, where a word's start is defined as either after a space or from the first character of the input text (for the first word). A "prefix" in the middle of a word is ignored.
E.g. if your input prefix is "arm" and the input text is "Dumbledore's army was fully armed for the impending armageddon" then the output list contains (y, ed, ageddon).
Test Cases
Assume case-sensitive, strings end after spaces. Input will not start with a space.
Removing duplicates is optional.
Input prefix: "1"
Input text:
"He1in aosl 1ll j21j 1lj2j 1lj2 1ll l1j2i"
Output: (ll, lj2j, lj2) - in any permutation
Input prefix: "frac"
Input text:
"fracking fractals fracted fractional currency fractionally fractioned into fractious fractostratic fractures causing quite a fracas"
Output: (king, tals, ted, tional, tionally, tioned, tious, tostratic, tures, as)
Input prefix: "href="https://www.astrotheme.com/astrology/"
Input text:
"(div style="padding: 0; background: url('https://www.astrotheme.com/images/site/arrondi_450_hd.png') no-repeat; text-align: left; font-weight: bold; width: 450px; height: 36px")
(div class="titreFiche" style="padding: 5px 0 0 6px")(a href="https://www.astrotheme.com/astrology/Nolwenn_Leroy" title="Nolwenn Leroy: Astrology, birth chart, horoscope and astrological portrait")Nolwenn Leroy(br /)
(/div)
(div style="text-align: right; border-left: 1px solid #b2c1e2; border-right: 1px solid #b2c1e2; width: 446px; padding: 1px 1px 0; background: #eff8ff")
(table style="width: 100%")(tr)(td style="width: 220px")
(div style="padding: 0; background: url('https://www.astrotheme.com/images/site/arrondi_450_hd.png') no-repeat; text-align: left; font-weight: bold; width: 450px; height: 36px")
(div class="titreFiche" style="padding: 5px 0 0 6px")(a href="https://www.astrotheme.com/astrology/Kim_Kardashian" title="Kim Kardashian: Astrology, birth chart, horoscope and astrological portrait")Kim Kardashian(br /)(span style="font-weight: normal; font-size: 11px")Display her detailed horoscope and birth chart(/span)(/a)(/div)
(/div)
(div style="padding: 0; background: url('https://www.astrotheme.com/images/site/arrondi_450_hd.png') no-repeat; text-align: left; font-weight: bold; width: 450px; height: 36px")
(div class="titreFiche" style="padding: 5px 0 0 6px")(a href="https://www.astrotheme.com/astrology/Julia_Roberts" title="Julia Roberts: Astrology, birth chart, horoscope and astrological portrait")Julia Roberts(br /)(span style="font-weight: normal; font-size: 11px")Display her detailed horoscope and birth chart(/span)(/a)(/div)
(td id="cfcXkw9aycuj35h" style="text-align: right")
(/div)"
Output: (Nolwenn_Leroy", Kim_Kardashian", Julia_Roberts")
The Winner
This is code-golf, so the fewest bytes wins. :)
Can accept the inputs in any way that works, as long as your code can solve arbitrary problems like the test cases.
2To be clear, the prefix has to be at the beginning of a word? If the second test case had the word 'diffraction' in it, would that change the output? – sundar - Reinstate Monica – 2018-07-16T12:11:27.850
"Prefix" here means ONLY if preceded by a space (or the start of the input).
So the "1" in "He1in" is ignored, and in "l1j2i", just as the "frac" in "diffraction" is ignored. – DrQuarius – 2018-07-16T12:16:23.383
2How can the
https://www.astrotheme.com/astrology/
can be a prefix when it's preceded byhref="
? – Neil – 2018-07-16T12:19:26.660Thank you Neil, that's very well spotted. I will have to add spaces. Thanks for noting. – DrQuarius – 2018-07-16T12:20:11.717
1May the suffix be empty? – user202729 – 2018-07-16T13:07:23.487
Empty suffix is fine, whether that leaves an empty slot in the output etc. It's also fine to ignore it. – DrQuarius – 2018-07-16T13:38:51.900
Also can there be two consecutive whitespaces (empty word) in the text? – user202729 – 2018-07-16T13:48:13.583
1I'd suggest allowing people to split on other white-space as well as spaces as a few seem to be doing so anyway. I'd also suggest saying there wont be multiple spaces in a row in the input (or somewhat equivalently that empty words may result in undefined behaviour). I suggest both these things since the main part of the challenge is not the splitting into words part (I would suggest just allowing a list of words or even just a word as input, but it's way too late now with 22 answers - something to note for future challenges though). – Jonathan Allan – 2018-07-16T19:02:40.980
1-1 to allowing splitting on other whitespaces now. It would make sense for the challenge to have been that originally, but changing now would split the answers into ones that do two different things. And this is not like the cases where some languages can't handle for eg. 64-bit numbers or something, here it just means implementing a slightly (possibly) more complex match, so it makes more sense to correct answers with wrong assumptions and perhaps add a test case to check for this too. – sundar - Reinstate Monica – 2018-07-16T20:00:42.067
Yes, the whitespace thing is a clear misstep by me for specifying 'space', I am happy for answers to do either. For the sake of the contest, any code that can solve my test cases is valid so things like "inputs with consecutive spaces" etc are fine since my test cases don't do that anyway. – DrQuarius – 2018-07-17T04:37:06.623