Well, if one considers test input a0, a1, a2 as series and some substructure in a given series as succession and defines a succession as a list of consecutive elements with constant difference between sucession members, the following arises:
(* given series *)
a0 = {3, 4, 5, 7, 10, 15, 23, 27};
a1 = {4, 6, 7, 8, 9, 10, 12, 15, 25};
a2 = {2, 6, 7, 10, 11, 12, 13, 14, 15, 25};
(* helpers *)
Clear[taker, successor]
taker[{l_List, o_Integer}] := First[l] /; Length[l] == 1 && o == 1
taker[{l_List, o_Integer}] := Drop[First[l], 1] /; Length[l] == 1 && o != 1
taker[{l_List, o_Integer}] := Union @@ l /; Length[l] != 1 && o == 1
taker[{l_List, o_Integer}] := Union @@ Drop[l, 1] /; Length[l] != 1 && o != 1
successor[l_List?VectorQ] := taker /@
Transpose[{#, Range[Length[#]]}] &[Split[Partition[l, 2, 1], (#1.{1, -1} == #2.{1, -1}) &]] /; OrderedQ[l]
finding successions within the series
In[75]:= successor /@ {a0, a1, a2}
Out[75]= {{{3, 4, 5}, {7}, {10}, {15}, {23}, {27}},
{{4, 6}, {7, 8, 9, 10}, {12}, {15}, {25}},
{{2, 6}, {7}, {10}, {11, 12, 13, 14, 15}, {25}}}
the smallest elements of successions
Map[First, #] & /@ (successor /@ {a0, a1, a2})
{{3, 7, 10, 15, 23, 27}, {4, 7, 12, 15, 25}, {2, 7, 10, 11, 25}}
the smallest elements of successions common to all series
In[99]:= Clear[smac]
smac = Intersection[Union @@ (Map[First, #] & /@ (successor /@ {a0, a1, a2})), a0, a1, a2]
Out[100]= {7, 10, 15}
get new series excluding the common smallest succession elements
In[102]:= {b0, b1, b2} = Complement[#, smac] & /@ {a0, a1, a2}
Out[102]= {{3, 4, 5, 23, 27}, {4, 6, 8, 9, 12, 25}, {2, 6, 11, 12, 13, 14, 25}}
finding again successions in the new series b0, b1, and b2; Attention: 8 is not smallest in any succession
In[103]:= successor /@ {b0, b1, b2}
Out[103]= {{{3, 4, 5}, {23}, {27}}, {{4, 6, 8}, {9}, {12}, {25}}, {{2, 6}, {11}, {12, 13, 14}, {25}}}
the smallest elements of these successions
In[104]:= Map[First, #] & /@ (successor /@ {b0, b1, b2})
Out[104]= {{3, 23, 27}, {4, 9, 12, 25}, {2, 11, 12, 25}}
getting smallest succession elements not in the non-home series; the X trick shouldn't be necessary
In[152]:= cp = Complement @@@ (Thread[
X[List /@ (Map[First, #] & /@ (successor /@ {b0, b1, b2})),
RotateLeft[Partition[{b0, b1, b2}, 2, 1, 1]]]] //. X -> Join)
Out[152]= {{3, 23, 27}, {9}, {2, 11}}
take the smallest of them
In[153]:= First /@ cp
Out[153]= {3, 9, 2}
Finally, discuss it
- no list came empty
- result is
{3,9,2}
, not {3,8,2}
- not sure whether the multi-valued usage of the term series in problem owner's description has been demangled correctly
- problem owner is free the decide that and to convert the whole thing into something useful
- notebook attached for convenience
- why the trick with the
X
ruling to Join
after threading X
was necessary?
Attachments: