const std = @import("std");
const print = std.debug.print;
const expect = std.testing.expect;

test "simple partition #1" {
    var arr = [_]u64{1,3,5};
    const res = bipartition(&arr, 0, @as(u64, arr.len-1), 2);
    std.log.warn("Res {}", .{res});
    try expect(res == 1);
}

pub fn bipartition(arr: []const u64, t1: u64, t2: u64, v: u64) u64 {
    std.log.warn("Arr called with {}, {}, {}", .{t1, t2, v});
    var x1:u64 = t1;
    var x2:u64 = t2;
    var x:u64 = undefined;

    if (arr.len <= 0) {
        return x1;
    }

    if (v < arr[x1]) {
        return x1;
    }

    if (v >= arr[t2]) {
        return t2 + 1;
    }

    while (x1 < x2 - 1) {
        std.log.warn("Round {},{}", .{t1, t2});
        x = (x1 + x2) / 2;
        if (arr[x] < v) {
            x1 = x;
        } else {
            x2 = x;
        }
    }

    return x2;
}

pub fn main() !void {
    print("Hello World {}!!!\n", .{1});
}