Пример #1
0
def test_pytriplets_2_c_lt300():
    """Testing pytriples with c values less than 100"""
    vals = set()
    gen = pytriple_gen(300)
    while len(vals) < len(lt300):
        vals.add(next(gen))
    assert vals == lt300
Пример #2
0
def p009():
    """
    for each possible pythagorean triplet:
        if 1000 is divisible by the sum of the triplet:
            RETURN: multiply product and the multiplier cubed
    """
    for tri in pytriple_gen(int(1000 // 2)):
        if 1000 % sum(tri) == 0:
            return iter_product(tri) * (1000 // sum(tri))**3
Пример #3
0
def pytiles(max_perimeter):
    """
    we are looking for triangles where the hypotenuse is divisible by the side
    mag of the inner square, which is the difference in the RAT legs,

    :param max_perimeter: max right triangle perimeter
    :return: number of triangles
    """
    count = 0
    for tri in pytriple_gen(max_perimeter // 2):
        if tri[2] % (tri[1] - tri[0]) == 0:
            count += max_perimeter // sum(tri)
    return count
Пример #4
0
def almost_equilateral(max_perimeter):
    """
    Generates almost equilateral triangles

    Almost-equilateral-triangles (AET):
        A triangle for which two sides are equal and the third differs by no
        more than one unit.


    An AET is really just 2 pythag-triple-triangles (back 2 back), where double
    the shortest leg in the triple +/-1 is equal to the hypotenuse (c). For an
    AET max perimeter of p, we look at pythagorean triples with c < p/3.
    """
    return ((tri[0] * 2, tri[-1], tri[-1])
            for tri in pytriple_gen((max_perimeter + 3) // 3)
            if abs(tri[-1] - (tri[0] * 2)) == 1)
Пример #5
0
    def test_pytriplets_c_lt300(self):
        """

        """
        p_set = {t for t in pytriple_gen(300)}
        assert self.lt300 == p_set
Пример #6
0
 def test_pytriplets_c_lt100(self):
     """
     Testing the primative pytriplet generator
     """
     p_set = {t for t in pytriple_gen(100)}
     assert self.lt100 == p_set
Пример #7
0
from math import sqrt
from pupy.maths import pytriple_gen


def tri_area(two_sides_len, other_side_length):
    return (sqrt(two_sides_len**2 - (other_side_length / 2.0)**2) *
            (other_side_length / 2.0)) % 1 == 0


print sum(
    sum(triple) for triple in [(tri[0] * 2, tri[2], tri[2]) for tri in [
        x for x in pytriple_gen((3 + 10**9) // 3) if abs(x[2] - 2 * x[0]) == 1
    ]])

# sum = 0
# for i in range(2, 1000000000//3):
#     if tri_area(i, i+1):
#         sum += 3*i+1
#     if tri_area(i, i-1):
#         sum += 3*i -1
#
# print sum
Пример #8
0
def test_pytriplets_2_c_lt100():
    """Testing pytriples with c values less than 100"""
    assert lt100 == set(pytriple_gen(100))
Пример #9
0
def test_pytriplets_c_lt300():
    """Testing pytriples with c values less than 100"""
    p_set = {t for t in pytriple_gen(300)}
    assert lt300 == p_set
Пример #10
0
def test_pytriplets_c_lt100():
    """Testing pytriples with c values less than 100"""
    assert {t for t in pytriple_gen(100)} == lt100