예제 #1
0
 // 指定された値よりも大きい値を持つ最初のインデックスを求めます。
 // これは、挿入先のインデックスを意味します。
 public static int IndexForInsert(IList <int> a, int v) => BinarySearch.First(i => a[i] > v, 0, a.Count);
예제 #2
0
 // 数当てゲーム
 // https://dentsu-ho.com/articles/6878
 public static int GuessNumber(Func <int, int> reply, int max) => BinarySearch.First(n => reply(n) >= 0, 1, max);
예제 #3
0
 public static double Sqrt(double v, int digits = 9) => BinarySearch.First(x => x * x >= v, Math.Min(1, v), Math.Max(1, v), digits);
예제 #4
0
        public static int IndexOfDescending(IList <int> a, int v)
        {
            var r = BinarySearch.First(i => a[i] <= v, 0, a.Count);

            return(r < a.Count && a[r] == v ? r : ~r);
        }