Example #1
0
File: p66.py Project: smbell/euler
def continued_fraction():
    large_x = 0
    for D in range(2, 1001):
        if et.is_sqr(D):
            continue
        d = 1
        m = 0
        a0 = int(math.sqrt(D))
        a = a0

        x1 = 1
        x = a
        y1 = 0
        y = 1

        while x**2 - D*(y**2) != 1:
            m = d * a - m
            d = (D - m * m) / d
            a = (a0 + m) / d

            x2 = x1
            x1 = x
            y2 = y1
            y1 = y

            x = a*x1 + x2
            y = a*y1 + y2

        if x > large_x:
            print '%d has x of %d' % (D, x)
            large_x = x
    return large_x
Example #2
0
File: p80.py Project: smbell/euler
def solve():
    getcontext().prec = 101
    total = 0
    for i in range(2, 100):
        if et.is_sqr(i):
            continue
        total += sum(Decimal(i).sqrt().as_tuple().digits[:100])
    return total
Example #3
0
File: p66.py Project: smbell/euler
def xdy(max_d):
    y = 1.0
    large_x = 0
    for d in range(167, max_d + 1):
        if d % 100 == 0:
            print 'd = %d' % (d,)
        if et.is_sqr(d):
            continue
        y2 = d * (y**2)
        while not et.is_sqr(y2 + 1):
            y += 1.0
            y2 = d * (y**2)
        x = math.sqrt(y2 + 1)
        if x > large_x:
            print '%d has x of %d' % (d, x)
            large_x = x
        y = 1.0
    return large_x
Example #4
0
File: p86.py Project: smbell/euler
def solve_2(target = 10**6):
    length = 2
    count = 0
    while count < target:
        length += 1
	wh = 3
	while wh <= 2 * length:
	    square_distance = wh**2 + length**2
	    if euler_tools.is_sqr(square_distance):
	        if wh <= length:
		    count += wh / 2
		else:
		    count += 1 + (length - (wh + 1) / 2)
            wh += 1
    return length
Example #5
0
File: p86.py Project: smbell/euler
def is_integer_solution(a, b, c):
    csd = compute_square_distance
    min_square_distance = min(csd(a,b,c), csd(b,c,a), csd(c,a,b))
    return euler_tools.is_sqr(min_square_distance)
Example #6
0
File: p66.py Project: smbell/euler
def next_y(x2, d):
    temp = (x2 - 1.0) / d
    if et.is_sqr(temp):
        return math.sqrt(temp)
    return int(math.sqrt(temp)) + 1.0
Example #7
0
File: p66.py Project: smbell/euler
def next_x(y2):
    if et.is_sqr(y2 + 1):
        return math.sqrt(y2 + 1)
    return int(math.sqrt(y2)) + 1.0