45
4
Given a printable ASCII string, split it into a list of non-empty strings with a new sub-string beginning every time a character, which has not previously been seen in the same case, occurs.
Examples
"mississippi" → ["m","i","ssissi","ppi"]
"P P & C G" → ["P"," P ","& ","C ","G"]
"AAA" → ["AAA"]
"Adam" → ["A","d","a","m"]
"" → []
Anecdote: The result will have between 0 and 95 elements. The 95th sub-string will necessarily continue until the end because at that point, all printable ASCII characters have begun a sub-string, so every additional character will have occurred before and thus cannot cause a new sub-string to begin.
1An example containing
"
and'
seems like a good idea. – Emigna – 2018-02-19T18:15:59.913Would
""
→[""]
be acceptable? – Arnauld – 2018-02-19T18:18:51.940Can I return a newline-separated string? Since the input contains only printable ASCII, that would be unambiguous. – Dennis – 2018-02-19T18:19:34.700
Yes, I thought that was a default output format for lists of strings. – Adám – 2018-02-19T18:21:29.550
5@Emigna That just messes with the example output format without bringing any further clarity. – Adám – 2018-02-19T18:22:19.480
@Arnauld I don't think so
– Mr. Xcoder – 2018-02-19T18:22:48.750@Arnauld No,
[""]
isn't a list of non-empty substrings. – Adám – 2018-02-19T18:22:59.857Can the input be a list of characters, and the output be a list of lists of characters?
("A","d","d","a","m","s")
=>(("A"),("d","d"),("a"),("m"),("s"))
– Brad Gilbert b2gills – 2018-02-19T18:51:46.493@BradGilbertb2gills Yes, that's covered by default I/Os. – Adám – 2018-02-19T18:53:02.120
Not sure if intentional but your
'P P & C G' → ["P"," P ","& ","C ","G"]
example uses single quotes on the left and double quotes on the right. – cole – 2018-02-19T19:24:16.490@cole Neither is part of the string or the output array, so I doubt it matters. They're just delimiters to show the start and end of the input, not part of it, and likewise for the elements of the output. – Fund Monica's Lawsuit – 2018-02-19T20:24:18.477
1If outputting as a newline-separated string, can there be a leading/trailing newline? – wastl – 2018-02-19T21:32:08.740
2@wastl Uh, I'll permit it in this case because it cannot indicate empty segments, although it does clash with my earlier ruling of
[""]
to be invalid. Sigh. – Adám – 2018-02-19T21:56:26.997Can there be both leading and trailing newlines? – Jo King – 2018-07-19T12:54:30.220
@JoKing Sure, why not? – Adám – 2018-07-19T14:49:40.783
Not specified...the first string of input Mississippi would be M i s SI ppi – RosLuP – 2019-03-08T08:46:25.143
@RosLuP It is actually indirectly specified in the anecdote. Since there may be up to 95 substrings, and there are only 95 printable ASCII characters, this challenge must be case sensitive. I'll add a clarification anyway. – Adám – 2019-03-08T09:56:31.620
Shouldn't
"Adam"
be["A","da","m"]
? I'm not sure why its being split on the seconda
. (Compare to"Mississippi"
: there is no break began the first and seconds
) – Draco18s no longer trusts SE – 2019-03-08T14:57:07.813@Draco18s which has not previously been seen in the same case – Adám – 2019-03-08T14:58:58.637