Пример #1
0
    public static IEnumerable <Triplet> Where(int maxFactor, int minFactor = 1, int sum = 0)
    {
        for (int _a = minFactor; _a < maxFactor - 1; _a++)
        {
            for (int _b = _a + 1; _b < maxFactor; _b++)
            {
                for (int _c = _b + 1; _c <= maxFactor; _c++)
                {
                    Triplet newTriplet = new Triplet(_a, _b, _c);

                    if (!newTriplet.IsPythagorean())
                    {
                        continue;
                    }

                    if (sum != 0 && newTriplet.Sum() != sum)
                    {
                        continue;
                    }

                    yield return(newTriplet);
                }
            }
        }
    }
Пример #2
0
 public static IEnumerable <Triplet> Where(int maxFactor, int minFactor = 1, int sum = 0)
 {
     for (int i = minFactor; i <= maxFactor; i += 1)
     {
         for (int j = i; j <= maxFactor; j += 1)
         {
             for (int k = j; k <= maxFactor; k += 1)
             {
                 var t = new Triplet(i, j, k);
                 if (t.IsPythagorean() && (sum == 0 || t.Sum() == sum))
                 {
                     yield return(t);
                 }
             }
         }
     }
 }
Пример #3
0
    public static IEnumerable <Triplet> Where(int maxFactor, int minFactor = 1, int sum = 0)
    {
        var triplets = new List <Triplet>();

        for (int a = minFactor; a <= maxFactor - 2; a++)
        {
            for (int b = a + 1; b <= maxFactor - 1; b++)
            {
                for (int c = b + 1; c <= maxFactor; c++)
                {
                    var triplet = new Triplet(a, b, c);
                    if (triplet.IsPythagorean() && (sum == 0 || triplet.Sum() == sum))
                    {
                        triplets.Add(triplet);
                    }
                }
            }
        }

        return(triplets);
    }
Пример #4
0
 public static IEnumerable <Triplet> Where(int maxFactor, int minFactor = 1, int sum = 0)
 {
     for (int i = minFactor; i <= maxFactor; i++)
     {
         for (int j = i; j <= maxFactor; j++)
         {
             for (int k = j; k <= maxFactor; k++)
             {
                 if (i * i + j * j == k * k)
                 {
                     var triplet = new Triplet(i, k, j);
                     if (sum == 0)
                     {
                         yield return(triplet);
                     }
                     if (triplet.Sum() == sum)
                     {
                         yield return(triplet);
                     }
                 }
             }
         }
     }
 }
Пример #5
0
 private static bool ShouldIncludeTriplet(int sum, Triplet triplet)
 {
     return triplet.IsPythagorean() && (sum == 0 || triplet.Sum() == sum);
 }
Пример #6
0
 private static bool ValidTriplet(Triplet triplet, int sum)
 {
     return(triplet.IsPythagorean() && (triplet.Sum() == sum || sum == 0));
 }
Пример #7
0
 private static bool ValidTriplet(Triplet triplet, int sum)
 {
     return triplet.IsPythagorean() && (triplet.Sum() == sum || sum == 0);
 }
Пример #8
0
 private static bool ShouldIncludeTriplet(int sum, Triplet triplet)
 {
     return(triplet.IsPythagorean() && (sum == 0 || triplet.Sum() == sum));
 }