PPaste!

Home - All the pastes - Authored by Thooms

Raw version

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
def closest_nums(N, first, second):
    closest_pair = None

    lookup = {N - x for x in first}
    sorted_lookup = sorted(list(lookup))

    for y in second:
        # dichotomy
        x = find_closest(y, sorted_lookup)

        if abs(x - y) < abs(closest_pair.x - closest_pair.y):
            closest_pair = Pair(x, y)

    return closest_pair