In this challenge you will take as input a non-empty list of binary values (these can be booleans or integers on the range 0-1), you should output all the ways to partition the list into non-empty sections such that no two adjacent equal values in the initial list are separated into different sections.
For example if the input is [1,1,0,0,1]
then [1,1],[0,0,1]
is a valid partition but [1,1,0],[0,1]
is not since the adjacent 0
s are divided.
This is code-golf so the goal is to minimize the size of your source code as measured in bytes.
Test cases
[1,0] ->
[ [[1,0]]
, [[1],[0]]
]
[1,1,1,1] ->
[ [[1,1,1,1]]
]
[1,1,0,0,1] ->
[ [[1,1,0,0,1]]
, [[1,1],[0,0,1]]
, [[1,1,0,0],[1]]
, [[1,1],[0,0],[1]]
]
11|001|
be valud? \$\endgroup\$0
and1
are fine as binary values. \$\endgroup\$