Skip to main content
deleted 319 characters in body
Source Link
user73941
user73941

In general it looks OK to me, but you could maybe consider the following:

1) Return a IEnumerable<int[]> instead of List<List<int>> and then yield the positive results when found:

            ...
            else if (sumSoFar == sum)
            {
              yield return new int[] { iValue, jValue, kValue };
            }...

2) 3 * (long)maxInput < (long)sum: This cast has really no meaning because sum never exceeds int.MaxValue. And if it had, you should make the same cast in the last test: 3 * sortedInput[0] > sum What you could do was to first check if 3 * (long)maxInput > int.MaxValue and then if 3 * maxInput < sum.

3) The names sumI, sumJ, sumK are somewhat misleading because they aren't sums. Better names would be valueI, -J, -K

  int valueI;
  int valueJ;
  int valueK;

43) For the fun of it, you could consider: Because you basically do the same same loop nested three times, it could be a candidate for a recursive function iterating over each addend and yielding all the positive sums. In that way you could generalize the algorithm to handle any number of addends...

In general it looks OK to me, but you could maybe consider the following:

1) Return a IEnumerable<int[]> instead of List<List<int>> and then yield the positive results when found:

            ...
            else if (sumSoFar == sum)
            {
              yield return new int[] { iValue, jValue, kValue };
            }...

2) 3 * (long)maxInput < (long)sum: This cast has really no meaning because sum never exceeds int.MaxValue. And if it had, you should make the same cast in the last test: 3 * sortedInput[0] > sum What you could do was to first check if 3 * (long)maxInput > int.MaxValue and then if 3 * maxInput < sum.

3) The names sumI, sumJ, sumK are somewhat misleading because they aren't sums. Better names would be valueI, -J, -K

  int valueI;
  int valueJ;
  int valueK;

4) For the fun of it, you could consider: Because you basically do the same same loop nested three times, it could be a candidate for a recursive function iterating over each addend and yielding all the positive sums. In that way you could generalize the algorithm to handle any number of addends...

In general it looks OK to me, but you could maybe consider the following:

1) Return a IEnumerable<int[]> instead of List<List<int>> and then yield the positive results when found:

            ...
            else if (sumSoFar == sum)
            {
              yield return new int[] { iValue, jValue, kValue };
            }...

2) The names sumI, sumJ, sumK are somewhat misleading because they aren't sums. Better names would be valueI, -J, -K

  int valueI;
  int valueJ;
  int valueK;

3) For the fun of it, you could consider: Because you basically do the same same loop nested three times, it could be a candidate for a recursive function iterating over each addend and yielding all the positive sums. In that way you could generalize the algorithm to handle any number of addends...

added 25 characters in body
Source Link
user73941
user73941

In general it looklooks OK to me, but you could maybe consider the following:

1) Return a IEnumerable<int[]> instead of List<List<int>> and then yield the positive results when found:

            ...
            else if (sumSoFar == sum)
            {
              yield return new int[] { iValue, jValue, kValue };
            }...

2) 3 * (long)maxInput < (long)sum: This cast has really no meaning because sum never exceeds int.MaxValue. And if it had, you should make the same cast in the last test: 3 * sortedInput[0] > sum What you could do was to first check if 3 * (long)maxInput > int.MaxValue and then if 3 * maxInput < sum.

3) The names sumI, sumJ, sumK isare somewhat misleading because they aren't sums. Better names would be valueI, -J, -K

  int iValue = -1;valueI;
  int jValue = -1;valueJ;
  int kValue = -1;valueK;

4) For the fun of it, you could consider: Because you basically do the same same loop nested three times, it could be a candidate for a recursive function iterating over each addend and yielding all the positive sums. In that way you could generalize the algorithm to handle any number of addends...

In general it look OK to me, but you could maybe consider the following:

1) Return a IEnumerable<int[]> instead of List<List<int>> and then yield the positive results when found:

            ...
            else if (sumSoFar == sum)
            {
              yield return new int[] { iValue, jValue, kValue };
            }...

2) 3 * (long)maxInput < (long)sum: This cast has really no meaning because sum never exceeds int.MaxValue. And if it had, you should make the same cast in the last test: 3 * sortedInput[0] > sum What you could do was to first check if 3 * (long)maxInput > int.MaxValue and then if 3 * maxInput < sum.

3) The names sumI, sumJ, sumK is somewhat misleading. Better names would be valueI, -J, -K

  int iValue = -1;
  int jValue = -1;
  int kValue = -1;

4) For the fun of it, you could consider: Because you basically do the same same loop nested three times, it could be a candidate for a recursive function iterating over each addend and yielding all the positive sums. In that way you could generalize the algorithm to handle any number of addends...

In general it looks OK to me, but you could maybe consider the following:

1) Return a IEnumerable<int[]> instead of List<List<int>> and then yield the positive results when found:

            ...
            else if (sumSoFar == sum)
            {
              yield return new int[] { iValue, jValue, kValue };
            }...

2) 3 * (long)maxInput < (long)sum: This cast has really no meaning because sum never exceeds int.MaxValue. And if it had, you should make the same cast in the last test: 3 * sortedInput[0] > sum What you could do was to first check if 3 * (long)maxInput > int.MaxValue and then if 3 * maxInput < sum.

3) The names sumI, sumJ, sumK are somewhat misleading because they aren't sums. Better names would be valueI, -J, -K

  int valueI;
  int valueJ;
  int valueK;

4) For the fun of it, you could consider: Because you basically do the same same loop nested three times, it could be a candidate for a recursive function iterating over each addend and yielding all the positive sums. In that way you could generalize the algorithm to handle any number of addends...

Source Link
user73941
user73941

In general it look OK to me, but you could maybe consider the following:

1) Return a IEnumerable<int[]> instead of List<List<int>> and then yield the positive results when found:

            ...
            else if (sumSoFar == sum)
            {
              yield return new int[] { iValue, jValue, kValue };
            }...

2) 3 * (long)maxInput < (long)sum: This cast has really no meaning because sum never exceeds int.MaxValue. And if it had, you should make the same cast in the last test: 3 * sortedInput[0] > sum What you could do was to first check if 3 * (long)maxInput > int.MaxValue and then if 3 * maxInput < sum.

3) The names sumI, sumJ, sumK is somewhat misleading. Better names would be valueI, -J, -K

  int iValue = -1;
  int jValue = -1;
  int kValue = -1;

4) For the fun of it, you could consider: Because you basically do the same same loop nested three times, it could be a candidate for a recursive function iterating over each addend and yielding all the positive sums. In that way you could generalize the algorithm to handle any number of addends...