package codejam;

import fixjava.Pair;

public class Utils {

	public static long minLong(long firstVal, long... otherVals) {
		long minVal = firstVal;
		for (int i = 0; i < otherVals.length; i++)
			minVal = Math.min(firstVal, otherVals[i]);
		return minVal;
	}

	public static int minInt(int firstVal, int... otherVals) {
		int minVal = firstVal;
		for (int i = 0; i < otherVals.length; i++)
			minVal = Math.min(firstVal, otherVals[i]);
		return minVal;
	}

	public static float minFloat(float firstVal, float... otherVals) {
		float minVal = firstVal;
		for (int i = 0; i < otherVals.length; i++)
			minVal = Math.min(firstVal, otherVals[i]);
		return minVal;
	}

	/**
	 * ArgMin returned as a Pair<Integer, Integer>(index, value). Array must
	 * have at least one value.
	 */
	public static Pair<Integer, Integer> argMin(int[] arr) {
		int min = arr[0];
		int argMin = 0;
		for (int i = 1; i < arr.length; i++) {
			if (arr[i] < min) {
				min = arr[i];
				argMin = i;
			}
		}
		return new Pair<Integer, Integer>(argMin, min);
	}

	/**
	 * ArgMax returned as a Pair<Integer, Integer>(index, value). Array must
	 * have at least one value.
	 */
	public static Pair<Integer, Integer> argMax(int[] arr) {
		int max = arr[0];
		int argMax = 0;
		for (int i = 1; i < arr.length; i++) {
			if (arr[i] > max) {
				max = arr[i];
				argMax = i;
			}
		}
		return new Pair<Integer, Integer>(argMax, max);
	}

}

package de.johanneslauber.codejam;

import java.io.IOException;

/**
 * 
 * @author Johannes Lauber - joh.lauber@googlemail.com
 * 
 */
public class Main {

	/**
	 * @author Johannes Lauber - joh.lauber@googlemail.com
	 * @param Args
	 */
	public static void main(String[] Args) {
		// solveProblem("input/A-small-practice.in", "StoreCredit");
		// solveProblem("input/A-large-practice.in", "StoreCredit");
		// solveProblem("input/B-small-practice.in", "ReverseWords");
		// solveProblem("input/B-large-practice.in", "ReverseWords");
		// solveProblem("input/C-small-practice.in", "T9Spelling");
		// solveProblem("input/C-large-practice.in", "T9Spelling");
		// solveProblem("input/A-small-practice.in", "SpeakinginTongues");
		solveProblem("input/B-large.in", "DancingGooglers");
	}

	/**
	 * 
	 * @author Johannes Lauber - joh.lauber@googlemail.com
	 * @param fileName
	 * @param problemName
	 */
	private static void solveProblem(String fileName, String problemName) {
		CaseProvider caseProvider = new CaseProvider();
		try {
			try {
				caseProvider.importFile(
						fileName,
						Class.forName("de.johanneslauber.codejam.model.impl."
								+ problemName + "Case"));

				caseProvider.solveCases(Class
						.forName("de.johanneslauber.codejam.model.impl."
								+ problemName + "Problem"));
			} catch (ClassNotFoundException e) {
				System.out.println("Error finding implemented Case: "
						+ e.getMessage());
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		} catch (IOException e) {
			System.out.println("Error reading file: " + e.getMessage());
		}
	}
}