def go_down(name, exists, lower, upper):
    """bisection to find first free slot
    """
    if upper - lower < 2:
        if exists(name + '-%d' % lower):
            return name + '-%d' % upper
        else:
            return name + '-%d' % lower
    else:
        mid = (upper + lower) // 2
        if exists(name + '-%d' % mid):
            return go_down(name, exists, mid, upper)
        else:
            return go_down(name, exists, lower, mid)
bisection to find first free slot
    
recipes/Python/577934_Find_unique_name_based_prefix__digit_log2n_/recipe-577934.py