4
(Inspired by the Keg utility of this challenge)
Given a non-empty input string, e.g. s c 1= e(a"E")
, split the input into even-odd chunks.
Example (Feel free to suggest more)
I can only think of this test case, fee free to suggest more.
This input string, when mapped to its code points, yields the list [115, 32, 99, 32, 49, 61, 32, 101, 40, 97, 34, 69, 34, 41]
. When applied modulo-2 for every item, this returns [1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1]
.
In this list let's find the longest possible chunk that is consistent with even and odd code points:
[1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1]
For the first chunk, this yields [1, 0, 1, 0, 1]
because this is the longest chunk that follows the pattern
Odd Even Odd Even Odd Even ...
or
Even Odd Even Odd Even Odd ...
. Adding another codepoint into [1, 0, 1, 0, 1, 1]
breaks the pattern, therefore it is the longest possible even-odd chunk that starts from the beginning of the string.
Using this method, we should split the input into chunks so that this rule applies. Therefore the input becomes (the ;
here is simply a separator; this can be any separator that is not an empty string, Including the string itself):
s c 1;= e(a"E")
However, returning a list of strings is also permitted.
Rules
This is code-golf so the shortest solution wins. Let it be known that flags don't count towards being in the pattern. They also don't count towards byte count in this challenge.
The input will only be in ASCII, and the mapping will always be in ASCII (as far as I can tell most golflangs use a superset of ASCII).
Answering some of the comments
You may output strings as lists of codepoints.
"Any separator" includes the input string itself.
You may insert other characters like the MATL answer, such as alphanumeric characters.
You may not use integers as input instead of ASCII. Doing that will trivialize the challenge.
2Some more test cases would be helpful. Also, can the input be empty? – Luis Mendo – 2019-12-22T13:56:52.837
@LuisMendo Other than leading to some confusion for the viewer, this will not affect the program execution, because this separator will also be interpreted as part of the input string. – None – 2019-12-22T14:02:24.763
Does "any separator that is not an empty string" include the input string itself? – Jonathan Allan – 2019-12-22T14:45:54.127
2May we insert other characters / strings like the MATL answer? – Jonathan Allan – 2019-12-22T15:02:40.400
4May we simply return a list of strings, like the Japt answer used to, and the 05AB1E answer does? – Jonathan Allan – 2019-12-22T15:04:47.113
5Can we use integers as input instead of ASCII? It seems needlessly complex to require ASCII as input when we only care about their code points. – Post Rock Garf Hunter – 2019-12-22T16:50:49.230
@WheatWizard, why ask that and not ask whether output can too. Feels like you may as well have asked "Can we take a list of the least significant bits and return a list of lists of bits", since that's all we really care about. I feel like dealing with the I/O was actually most of the challenge here. – Jonathan Allan – 2019-12-23T13:16:21.040
1...Can output be a list of lists of code-points? – Jonathan Allan – 2019-12-23T13:17:08.850
... A string is technically a list of codepoints. – None – 2019-12-23T13:17:41.530
@LuisMendo I have edited the answers into the challenge body. May you point out the parts that are unclearly specified? – None – 2019-12-23T14:11:40.000
I have removed my comments that have been addressed. I suggest you do not refer to specific comment numbers in the challenge text. Comments are temporary – Luis Mendo – 2019-12-24T12:20:23.927