#import "Basic";
#import "File";
#import "String";
#import "Math";
#import "Sort";
#import "Hash_Table";
#import "Hash";

#load "PriorityQueue.jai";
#load "Deque.jai";

array_add_ordered :: (arr: *[..]$T, t: T, cmp: (T, T) -> $R) -> *T {
    index := 0;

    while index < arr.count {
        if cmp((<<arr)[index], t) > 0 {
            break;
        }
        index += 1;
    }

    if index == arr.count {
        array_add(arr, t);
    } else {
        array_insert_at(arr, t, index);
    }

    return *(<<arr)[index];
}


lcm :: (d1: s64, d2: s64) -> s64 {
    return (d1 / gcm(d1, d2)) * d2;
}

gcm :: (d1: s64, d2: s64) -> s64 {
    smaller := min(d1, d2);
    bigger  := max(d1, d2);

    while true {
        remainder := bigger % smaller;

        if remainder == 0  return smaller;

        bigger = smaller;
        smaller = remainder;
    }

    return 0;
}

Direction :: struct {
    x: s32;
    y: s32;
}

Grid :: struct {
    width: s64;
    height: s64;
    grid: string;
}