Hello community. I have created a function and would like to know if it is worth submitting in Function Repository or if there is already something simpler that does this same job? If anyone can give any opinion on this I will be very grateful.
I modestly have created a function that can interleave two lists by alternating their terms (unlike Riffle, which only fits the terms into gaps, this function does this keeping the same number of terms as it replaces them by both functions simultaneously).
- It works like this:
If the third term inside the function (“c_”) is {} the function does this automatically in a 1 to 1 pattern of each group:
Alternate[a_, b_] := Alternate[a, b, {}]
Alternate[a_, b_, c_] :=
PadRight[a*
PadRight[
Take[Flatten@Table[If[c == {}, {1, 0}, c], Count[a, _]],
Min[Count[a, _], Count[b, _]]], Count[a, _], 1],
Max[Count[a, _], Count[b, _]]] +
PadRight[b*
PadRight[
Take[Flatten@Table[Abs[If[c == {}, {1, 0}, c] - 1], Count[b, _]],
Min[Count[a, _], Count[b, _]]], Count[b, _], 1],
Max[Count[a, _], Count[b, _]]]
r = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20};
s = {3, 5, 7, 9, 11, 13, 15, 17, 19, 21};
Alternate[r, s]
Alternate[s, r]

The function works even with lists of different sizes, keeping the terms in excess unchanged:
p = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20};
q = {3, 5, 7, 9, 11, 13, 15, 17};
Alternate[p, q]
Alternate[q, p]

Or you can change the third term (“c”) in the function to any pattern (eg: {0,1,1,1}). Where “1” refers to the first term (“a”) from within the function while “0” refers to the term (“b”) from within the function:
t = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20};
u = {3, 5, 7, 9, 11, 13, 15, 17};
Alternate[t, u, {0, 1, 1, 1}]
Alternate[u, t, {0, 1, 1, 1}]

I would like to know if is this a good idea or there is a simpler way to do this? Is it worth sending a repository request?
Thank you.

