Ejemplo n.º 1
0
    def generate_operations(self):
        """
        Generates 3 fractions combinations.

        Returns a tuple like (t1, b1, t2, b2, t3, b3).
        """
        fractions = list(generate_one_dimension_fractions(self.limit))
        for terms in itertools.product(fractions, fractions, fractions):
            yield terms[0] + terms[1] + terms[2]
Ejemplo n.º 2
0
 def generate_operations(self):
     """
     Generate terms like 2 * 1/2, 2 * 1/3, LIMIT * 3/LIMIT and so on.
     """
     fractions = list(generate_one_dimension_fractions(self.limit))
     interval = xrange(2, self.limit + 1)
     for term1, (term2, base2) in itertools.product(interval, fractions):
         if term2 == base2:
             continue
         yield term1, term2, base2
 def generate_operations(self):
     """
     Combines two dimensions of terms. Avoids two terms with same base.
     """
     fractions = list(generate_one_dimension_fractions(self.limit))
     for terms in itertools.product(fractions, fractions):
         term1, base1, term2, base2 = terms[0] + terms[1]
         if base1 == base2:
             continue
         yield term1, term2, base1, base2
Ejemplo n.º 4
0
 def generate_operations(self):
     """
     Combines a list of fractions with a list of integers.
     """
     fractions = list(generate_one_dimension_fractions(self.limit))
     interval = xrange(2, self.limit + 1)
     for terms in itertools.product(interval, fractions):
         term2 = terms[0]
         term1, base1 = terms[1]
         if term1 == base1:
             continue
         yield term1, base1, term2
Ejemplo n.º 5
0
    def generate_operations(self):
        """
        Combines two dimensions of terms.

        Avoids terms with same base and avoid negative result subtractions.
        """
        fractions = list(generate_one_dimension_fractions(self.limit))
        for terms in itertools.product(fractions, fractions):
            term1, base1, term2, base2 = terms[0] + terms[1]
            if base1 == base2:
                continue

            if (term1 / float(base1)) <= (term2 / float(base2)):
                continue  # avoid zero or negative

            yield term1, term2, base1, base2
    def generate_operations(self):
        """
        Generates options for irreducible fractions exercises.

        Make fractions from 2/3 until N-1/N, ignoring any fraction
        without a simplified version.
        """
        interval = generate_one_dimension_fractions(self.limit, start=2)
        for term1, term2 in interval:
            simplified = fractions.Fraction(term1, term2)
            term3, term4 = (simplified.numerator, simplified.denominator)

            # Ignore equal fractions (that was not simplified)
            if term1 == term3 and term2 == term4:
                continue

            yield (term1, term2, term3, term4)
Ejemplo n.º 7
0
 def generate_operations(self):
     """Generates fractions from 1/2 until limit/limit."""
     fractions = list(generate_one_dimension_fractions(self.limit))
     for terms in itertools.product(fractions, fractions):
         yield terms[0] + terms[1]
Ejemplo n.º 8
0
 def generate_operations(self):
     fractions = list(generate_one_dimension_fractions(self.limit))
     for terms in itertools.product(fractions, fractions):
         term1, base1, term2, base2 = terms[0] + terms[1]
         yield term1, term2, base1, base2