Wolfram Computation Meets Knowledge

BisectList

Contributed by: George Beck

Make a pair of lists consisting of alternate terms from the original list

ResourceFunction["BisectList"][{a1,a2,a3,a4,a5,a6,}]

makes the list {{a1,a3,a5,{a2,a4,a4,}}.

Details and Options

ResourceFunction["BisectList"] is a partial inverse function of .
The two sublists have equal lengths.
If the input list has an odd number of terms, the last term is ignored.
The argument can be an expression other than a list.

Examples

Basic Examples

The lists being riffled have the same length:

In[1]:=
Riffle[{1, 2, 3}, 100 {1, 2, 3}]
Out[1]=

BisectList gives back the sublists:

In[2]:=
ResourceFunction["BisectList"]@%
Out[2]=

Here the riffled lists have different lengths:

In[3]:=
Riffle[{1, 2, 3, 4}, 100 {1, 2, 3}]
Out[3]=

BisectList ignores the last term:

In[4]:=
ResourceFunction["BisectList"]@%
Out[4]=

Here the head of the expression is not a list:

In[5]:=
ResourceFunction["BisectList"][fgh /@ Range[7]]
Out[5]=

Scope

Add consecutive pairs of a list:

In[6]:=
Total@ResourceFunction["BisectList"]@Range[20]
Out[6]=

BisectList twice:

In[7]:=
ResourceFunction["BisectList"] /@ ResourceFunction["BisectList"]@Range[32]
Out[7]=

Pull out the interleaved subsequences, making them both positive:

In[8]:=
(-1)^Range[20] RandomInteger[{1, 9}, 20]
Out[8]=
In[9]:=
{-1, 1} ResourceFunction["BisectList"][%]
Out[9]=

Resource History