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 – 8 years agoWould
""→[""]be acceptable? – Arnauld – 8 years agoCan I return a newline-separated string? Since the input contains only printable ASCII, that would be unambiguous. – Dennis – 8 years ago
Yes, I thought that was a default output format for lists of strings. – Adám – 8 years ago
5@Emigna That just messes with the example output format without bringing any further clarity. – Adám – 8 years ago
@Arnauld I don't think so
– Mr. Xcoder – 8 years ago@Arnauld No,
[""]isn't a list of non-empty substrings. – Adám – 8 years agoCan 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 – 8 years ago@BradGilbertb2gills Yes, that's covered by default I/Os. – Adám – 8 years ago
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 – 8 years ago@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 – 8 years ago
1If outputting as a newline-separated string, can there be a leading/trailing newline? – wastl – 8 years ago
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 – 8 years agoCan there be both leading and trailing newlines? – Jo King – 7 years ago
@JoKing Sure, why not? – Adám – 7 years ago
Not specified...the first string of input Mississippi would be M i s SI ppi – RosLuP – 7 years ago
@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 – 7 years ago
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 – 7 years ago@Draco18s which has not previously been seen in the same case – Adám – 7 years ago