MATL, 20 bytes
TiodgvYsG8XQ!"@gto?P
Input is a column array, using ;
as separator.
Try it online!
Explanation
Consider as an example the input array [1;2;3;5;7;4;6;7;9]
. The first part of the code, Tiodgv
, converts this array into [1;1;1;0;0;1;0;1;0]
, where 1
indicates a change of parity. (Specifically, the code obtains the parity of each entry of the input array, computes consecutive differences, converts nonzero values to 1
, and prepends a 1
.)
Then Ys
computes the cumulative sum, giving [1;2;3;3;3;4;4;5;5]
. Each of these numbers will be used as a label, based on which the elements of the input will be grouped. This is done by G8XQ!
, which splits the input array into a cell array containing the groups. In this case it gives {[1] [2] [3;5;7] [4;6] [7;9]}
.
The rest of the code iterates ("
) on the cell array. Each constituent numeric array is pushed with @g
. to
makes a copy and computes its parity. If (?
) the result is truthy, i.e. the array contents are odd, the array is flipped (P
).
The stack is implicitly displayed at the end. Each numeric vertical array is displayed, giving a list of numbers separated by newlines.
4>
Also, I'm not sure what further numeric computation refers to. Does it mean that I cannot return an immutable tuple or simply print the numbers? – Dennis – 2016-07-03T05:10:07.407
@Dennis Updated as you suggested. It is to prevent input/output as string. Any suggestion for better wording? – Adám – 2016-07-03T05:14:59.790
4Why do you want to prevent string output? – Dennis – 2016-07-03T05:16:02.060
@Dennis Good point taken. – Adám – 2016-07-03T05:17:07.863
Related. Maybe dupe? – xnor – 2016-07-03T07:01:13.557
@xnor This one requires much more processing to find the parts that should be reversed. – Adám – 2016-07-03T07:07:45.387
2Yes, looking at the other challenge, most of the answers rely on splitting on zeroes, whereas here you'd have to split on a condition, which most languages don't have a built-in for. – xnor – 2016-07-03T07:14:22.440
@LuisMendo Yes. – Adám – 2016-07-03T13:34:54.727