#!/usr/bin/ruby

#
## https://rosettacode.org/wiki/Binary_search
#

func binary_search(array, value, low, high) {
    high < low && return -1;
    var middle = (high+low / 2 -> int);
 
    if (value < array[middle]) {
        return binary_search(array, value, low, middle-1);
    }
    elsif (value > array[middle]) {
        return binary_search(array, value, middle+1, high);
    }
 
    return middle;
}

say binary_search(@(1..100), 23, 0, 99);
