예제 #1
0
def solutions(limit):
    # We seek x_k^2 - 3y_k^2 = 4
    # Where 3*n - sign = x_k
    x_mult, y_mult, relation = get_recurrence([1, -3])
    starting_points = all_values_on_form([1, -3], 4)
    series = [start_to_series(initial, x_mult, 'x')
              for initial in starting_points]
    result = [pair[0] for pair in series
              if pair[0] % 3 != 0 and pair[0] > 0]
    while max(result) < 2 * limit:
        next = [pair[1] for pair in series
                if pair[1] % 3 != 0 and pair[1] > 0]
        result.extend(next)
        series = [recurrence_next(relation, values) for values in series]
    # We seek perimeters n + n + (n + sign) = 3n + sign
    # We currently have 3n - sign, so if we can determine the sign
    # If value == 1 mod 3, then 3n - sign == 1, hence sign = -1
    # and 3n + sign = 3n - 1 = value - 2
    # If value == -1 mod 3, then 3n - sign == -1, hence sign = 1
    # and 3n + sign = 3n + 1 = value + 2
    result = sorted(((value + 2) if value % 3 == 2 else (value - 2))
                    for value in result)
    # The first two solutions are 1-1-0 and 1-1-2, which are both degenerate
    return [perimeter for perimeter in result
            if perimeter < limit and perimeter not in (2, 4)]
예제 #2
0
def solutions(limit):
    # We seek 5x_k^2 - y_k^2 = 1
    # Where L = x_k
    x_mult, y_mult, relation = get_recurrence([5, -1])
    starting_points = all_values_on_form([5, -1], 1)
    series = [start_to_series(initial, x_mult, 'x')
              for initial in starting_points]
    result = [pair[0] for pair in series if pair[0] > 1]
    while len(result) < 2*limit:
        next = [pair[1] for pair in series if pair[1] > 1]
        result.extend(next)
        series = [recurrence_next(relation, values) for values in series]
    return sorted(result)[:limit]
예제 #3
0
def golden_nuggets(limit):
    # We seek 5x_k^2 - y_k^2 = 4
    # Where 5n + 1 = y_k
    x_mult, y_mult, relation = get_recurrence([5, -1])
    starting_points = all_values_on_form([5, -1], 4)
    series = [start_to_series(initial, y_mult, 'y')
              for initial in starting_points]
    nuggets = [pair[0] for pair in series
               if pair[0] % 5 == 1 and pair[0] > 1]
    while len(nuggets) < 2 * limit:
        next = [pair[1] for pair in series
                if pair[1] % 5 == 1 and pair[1] > 1]
        nuggets.extend(next)
        series = [recurrence_next(relation, values) for values in series]
    return sorted([(value - 1) / 5 for value in nuggets])[:limit]
예제 #4
0
def main(verbose=False):
    # y = 2T - 1, T > 10**12 implies the following:
    LOWER_LIMIT = 2 * (10 ** 12) - 1

    # We seek 2x^2 - y^2 = 1
    x_mult, y_mult, relation = get_recurrence([2, -1])
    starting_points = all_values_on_form([2, -1], 1)
    series = [start_to_series(initial, y_mult, 'y')
              for initial in starting_points]
    result = [pair[0] for pair in series]
    while max(result) <= LOWER_LIMIT:
        result.extend([pair[1] for pair in series])
        series = [recurrence_next(relation, values) for values in series]

    min_y = min(y for y in result if y > LOWER_LIMIT)
    min_x = sqrt((1 + min_y ** 2) / 2)
    return int((min_x + 1) / 2)