List of utility methods to do Array Sum
int | summarizeIntegerArray(int[] numbers) Takes an array of integers and return the summation int total = 0; for (int number : numbers) { total += number; return total; |
String[] | summarizeNumbersAsString(int[] numbers) Return a list of strings were adjacent values are clumped together. Set<Integer> set = new HashSet<Integer>(); for (int number : numbers) { set.add(number); List<Integer> sortedNumbers = new ArrayList<Integer>(set); Collections.sort(sortedNumbers); List<String> summarizedStrings = new ArrayList<String>(); Integer currentRunMin = null; ... |
double | summation(double[] values) summation double sum = 0.0; int size = values.length; for (int i = 0; i < size; i++) { sum += values[i]; return sum; |
double | sumMaxK(double[] x, int k) sum Max K int[] ids = sort(x); if (k > ids.length) { k = ids.length; double s = 0; for (int i = ids.length - 1; (ids.length - 1 - i + 1) <= k; i--) { s = s + x[ids[i]]; return s; |
int | summedDifference(int[][] matrix, short topX, short botX, short row) summed Difference int n = matrix[0].length - 1; int sums[] = new int[4]; sums[1] = matrix[topX][row]; sums[0] = matrix[n][row] - sums[1]; sums[2] = matrix[botX][n] - matrix[botX][row]; sums[3] = matrix[n][n] - sums[0] - sums[2] - sums[1]; Arrays.sort(sums); return sums[3] - sums[0]; ... |
double | sumMinMax(double[] values, int out[]) The sum of the entries in the specified portion of the input array, or Double.NaN if the designated subarray is empty.
int max = 0; int min = 0, i; double sum = values[0]; int n = values.length; for (i = 1; i < n; i++) { sum += values[i]; if (values[i] > values[max]) max = i; ... |
double | sumMult(double[] aArray1, double[] aArray2) Computes the sum of the multiplications of the given arrays. double result = 0; for (int i = 0; i < aArray1.length; ++i) { result += aArray1[i] * aArray2[i]; return result; |
double | sumNaive(final double... values) sum Naive double ret = 0; for (final double x : values) ret += x; return ret; |
int | sumOf(int... values) Return the sum of all given Integer values int retval = 0; for (int value : values) { retval += value; return retval; |
double | sumOfArray(double[] array) sum Of Array double sum = 0; for (double x : array) { sum += x; return sum; |