Tag Info

Hot answers tagged

5

Ordering[Ordering[data]] (* {3,1,2} *)


1

list1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; idx = GatherBy[list1, Mod[#, 3] &] list2 = {"It", "is", "only", "the", "morning", "the", "man", "complained", "I", "shall", "consider", "nothing"}; Part[list2, #] & /@ idx


1

list1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; list2 = {"It", "is", "only", "the", "morning", "the", "man", "complained", "I", "shall", "consider", "nothing"}; GatherBy[Transpose[{list1, list2}], Mod[#[[1]], 3] &][[All, All, 2]] (* {{"It", "the", "man", "shall"}, {"is", "morning", "complained", "consider"}, {"only", "the", "I", ...


1

Here are a couple of possibilities. inOrder1[a_List, a_] := 0 inOrder1[a_List, b_List] /; MatrixQ[{a, b}, IntegerQ] := Sign[First[a - b /. 0 -> Sequence[]]] In[8]:= inOrder1[{1, 2, 1}, {1, 4, 0}] (* Out[8]= -1 *) inOrder2[a_List, b_List] /; MatrixQ[{a, b}, IntegerQ] := Catch[ Module[{sg}, Scan[If[(sg = Sign[#[[1]] - #[[2]]]) != 0, Throw[sg]] ...



Only top voted, non community-wiki answers of a minimum length are eligible