QDBordtoshred / WEni

MIT License
0 stars 0 forks source link

FRQ #1 #18

Open QDBordtoshred opened 7 months ago

QDBordtoshred commented 7 months ago

(a) arraySum method

    int sum = 0;
    for (int value : arr) {
        sum += value;
    }
    return sum;
}

The arraySum method takes a one-dimensional array as input and calculates the sum of its entries using a simple for-each loop.

(b) rowSums method

public static int[] rowSums(int[][] arr2D) {
    int[] sums = new int[arr2D.length];

    for (int i = 0; i < arr2D.length; i++) {
        sums[i] = arraySum(arr2D[i]);
    }

    return sums;
}

The rowSums method iterates through each row of the two-dimensional array arr2D and uses the previously defined arraySum method to calculate the sum of each row. The sums are then stored in a one-dimensional array.

(c) isDiverse method

public static boolean isDiverse(int[][] arr2D) {
    int[] rowSums = rowSums(arr2D);

    for (int i = 0; i < rowSums.length - 1; i++) {
        for (int j = i + 1; j < rowSums.length; j++) {
            if (rowSums[i] == rowSums[j]) {
                return false; // If any two row sums are equal, the array is not diverse
            }
        }
    }

    return true; // All row sums are unique, array is diverse
}

The isDiverse method calculates the row sums using the rowSums method and then checks if there are any duplicate row sums. If there are, it returns false, indicating that the array is not diverse. Otherwise, it returns true.

aidenhuynh commented 7 months ago

Comments:

The requirement for assignment is a Jupyter Notebook that runs the code, correctly identifying the FRQ type, and a reflection for the problem.

Score:

0.6/0.9

VINERAJ commented 7 months ago

Your code should be in a Jupyter Notebook, and you show have an issue with the connection between the FRQ and PBL. For this FRQ, I will give you a score of 0.63/0.9