Mathematica, 120 130 bytes
Edit
This version works with arrays of varying sizes.
l = List;
g = Grid@Cases[Outer[l, Sequence @@ MapIndexed[l, #, {2}], 1]~Flatten~(Length[#] - 1),
x_ /; LessEqual @@ x[[All, 1]] == True :> x[[All, 2, 2]] - 1] &
Usage
g@{{10, 20, 30}, {1, 22, 3}}
g@{{1, 5, 7, 10}, {2, 6, 6, 8, 12}, {4, 5, 9}}
g@{{10, 20, 30}, {1, 2, 3}}
g@{{1, -2, 3}, {-12, -7, 8, 9, 6}, {3, 99, 9}, {100, 10, -23}, {90, 10}}
Explanation
Using the first example from above,
a = {{10, 20, 30}, {1, 22, 3}}
MapIndexed
sets indices for all the elements. N.B.: Mathematica begins counting with 1. (We'll later take that into account.)
MapIndexed[l, a, {2}]
{{{10, {1, 1}}, {20, {1, 2}}, {30, {1, 3}}}, {{1, {2, 1}}, {22, {2,
2}}, {3, {2, 3}}}}
Outer
generates all lists, each a candidate as a sandwich array, and the indices of their elements; %
contains the results from the prior output. The numbers, 10
and 22
which I highlighted after they were output, refer to a sandwich array {10,22}
that has yet to be identified as such.
Outer[l, Sequence @@ %, 1]~Flatten~(Length[a] - 1)
{{{10, {1, 1}}, {1, {2, 1}}}, {{10, {1, 1}}, {22, {2, 2}}}, {{10, {1,
1}}, {3, {2, 3}}}, {{20, {1, 2}}, {1, {2, 1}}}, {{20, {1,
2}}, {22, {2, 2}}}, {{20, {1, 2}}, {3, {2, 3}}}, {{30, {1,
3}}, {1, {2, 1}}}, {{30, {1, 3}}, {22, {2, 2}}}, {{30, {1,
3}}, {3, {2, 3}}}}
Cases
tests each element of the above to determine whether a LessEqual
(less than or equal) relation holds. The results shown below are those instances in which array sandwiches were detected. Once again, I highlighted {10,22}
in the output.
Cases[%, x_ /; LessEqual @@ x[[All, 1]] == True]
{{{10, {1, 1}}, {22, {2, 2}}}, {{20, {1, 2}}, {22, {2, 2}}}}
%%
refers to the penultimate results. :>
, [ RuleDelayed] returns thos parts of the instances of interest, namely, the indices of the array sandwiches. -1
corrects for the fact that Mathematica begins arrays with 1 instead of 0.
Cases[%%, x_ /; LessEqual @@ x[[All, 1]] == True :> x[[All, 2, 2]] - 1]
{{0, 1}, {1, 1}}
Grid
displays the results in a grid. The first row 0 1
means the that element 0 from the first sublist (i.e. 10) and the element 1 from the second sublist (i.e. 22) constitute the first sandwich array that was found.
Grid@%
0 1
1 1