Finding first element of a Mathematica list greater than a ...
stackoverflow.com › questions › 3671937Aug 27, 2011 · binarySearch = Compile[{{arg, _Integer}, {list, _Integer, 1}}, Module[ {min = 1, max = Length@list, i, x}, While[ min <= max, i = Floor[(min + max)/2]; x = list[[i]]; Which[ x == arg, min = max = i; Break[], x < arg, min = i + 1, True, max = i - 1 ] ]; If[ 0 == max, 0, max ] ], CompilationTarget -> "C", RuntimeOptions -> "Speed" ];
Take—Wolfram Language Documentation
reference.wolfram.com › language › refgives the first n elements of list. Take [ list, - n] gives the last n elements of list. Take [ list, { m, n }] gives elements m through n of list. Take [ list, seq1, seq2, …] gives a nested list in which elements specified by seq i are taken at level i in list. Details Examples open all Basic Examples (6) Take the first 4 elements from a list: