// Arup Guha
// 2/17/2026
// Solution to COP 3330 Quiz #2 Questions 1, 2, 3, 7

import java.util.*;

public class Quiz2 {

	public static void main(String[] args) {

		// Couple of quick basket tests.
		System.out.println(numBaskets(5, 4, 99, 2000));
		System.out.println(numBaskets(200, 2, 80007, 7));
		
		// Some randomly generated integers.
		int[] lotsOfNums = getRndInts(new Random(), 20);
		for (int i=0; i<lotsOfNums.length; i++)
			System.out.print(lotsOfNums[i]+" ");
		System.out.println();
		
		// Our favorite pyramid.
		printInvertedPyramid(9);
		
		// Row-col test...should probably run more.
		int[][] test = {{6,20,13,4,5},{1,30,7,9,3},{9,15,10,8,2}};
		System.out.println(maxRowOrColSum(test));
	}

	// Returns the number of fruit baskets we can make with aTotal apples and oTotal
	// oranges. Each basket must have aPerBasket apples and oPerBasket oranges.
	public static int numBaskets(int aPerBasket, int oPerBasket, int aTotal, int oTotal) {
		return Math.min(aTotal/aPerBasket, oTotal/oPerBasket);
	}
	
	// Returns an array of size randomly generated integers in between 0 and 100, inclusive.
	public static int[] getRndInts(Random rndObj, int size) {
		
		// Make the array of the right size.
		int[] res = new int[size];
		
		// For each entry put a randomly generated integer in range, using rndObj.
		for (int i=0; i<size; i++)
			res[i] = rndObj.nextInt(101);
		return res;
	}
	
	// Prints an inverted pyramid with n rows.
	public static void printInvertedPyramid(int n) {
	
		// i will represent the number we're printing on that row.
		for (int i=n; i>=1; i--) {
			
			// First we must print n-i spaces.
			for (int j=0; j<n-i; j++)
				System.out.print(" ");
			
			// Then i space separated copies of the number i.
			for (int j=0; j<i; j++)
				System.out.print(i+" ");
			
			// Go to the next line.
			System.out.println();
		}
	}
	
	// Returns the maximum sum of any row or column.
	public static int maxRowOrColSum(int[][] array) {
	
		// Store best row sum here. 0 is guaranteed to be a safe initial value.
		int res = 0;
		
		// i represents the row we are currently summing.
		for (int i=0; i<array.length; i++) {
			
			// Add up all values of row i into rSum.
			int rSum = 0;
			for (int j=0; j<array[i].length; j++)
				rSum += array[i][j];
			
			// Update our result if this one's better.
			res = Math.max(res, rSum);
		}
		
		// j represents the column we are currently summing.
		for (int j=0; j<array[0].length; j++) {
			
			// Add up the values on column j.
			int cSum = 0;
			for (int i=0; i<array.length; i++)
				cSum += array[i][j];
			
			// Update if this is better than anything seen before.
			res = Math.max(res, cSum);
		}
		
		// Ta da!
		return res;
	}
}