PPaste!

Home - All the pastes - Authored by Thooms

Raw version

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

    sorted_first = sorted(first)

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

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