Esempio n. 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);
                }
            }
        }
    }
Esempio n. 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);
                 }
             }
         }
     }
 }
Esempio n. 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);
    }
Esempio n. 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);
                     }
                 }
             }
         }
     }
 }
Esempio n. 5
0
 private static bool ShouldIncludeTriplet(int sum, Triplet triplet)
 {
     return triplet.IsPythagorean() && (sum == 0 || triplet.Sum() == sum);
 }
 private static bool ValidTriplet(Triplet triplet, int sum)
 {
     return(triplet.IsPythagorean() && (triplet.Sum() == sum || sum == 0));
 }
 private static bool ValidTriplet(Triplet triplet, int sum)
 {
     return triplet.IsPythagorean() && (triplet.Sum() == sum || sum == 0);
 }
Esempio n. 8
0
 private static bool ShouldIncludeTriplet(int sum, Triplet triplet)
 {
     return(triplet.IsPythagorean() && (sum == 0 || triplet.Sum() == sum));
 }