/* Written by Jeff Kaufman : 2005 * * released under the GPL * */ public class csprb { public static void main(String[] args) { if(args.length == 1 && args[0].equals("all")) findAll(); else if(args.length == 3) { findSpecific(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2])); } else { System.out.println("Usage: "); System.out.println(" java csbrb all"); System.out.println(" java csprb 6 7 8"); System.out.println(""); System.exit(1); } } public static void findAll() { int waysbust; for (int i = 2 ; i <= 12 ; i++) for (int j = 2 ; j <= 12 ; j++) if (j > i) for (int k = 2 ; k <= 12 ; k++) if (k > j) { waysbust = findWaysBust(i,j,k); System.out.println(waysbust + " : " + i + " " + j + " " + k + " : " + chanceThreeDec(waysbust,6*6*6*6)); } } public static void findSpecific(int a, int b, int c) { int ways = 6*6*6*6; int waysbust = findWaysBust(a,b,c); System.out.println("\nResults for " + a + " " + b + " " + c + " " + ":\n" + " ways to roll four dice: " + ways + "\n" + " ways to bust : " + waysbust + "\n" + " chance of busting : " + chanceThreeDec(waysbust,ways) + "%\n"); } public static String chanceThreeDec(int waysbust, int ways) { return "" + (((int)((waysbust/((double)ways)*100)*1000))/1000.0); } public static int findWaysBust(int a, int b, int c) { int waysbust = 0; for(int i = 1 ; i <= 6 ; i++) for(int j = 1 ; j <= 6 ; j++) for(int k = 1 ; k <= 6 ; k++) for(int l = 1 ; l <= 6 ; l++) waysbust += f(i,j,k,l,a) || f(i,j,k,l,b) || f(i,j,k,l,c) ? 0 : 1; return waysbust; } public static boolean f(int i, int j, int k, int l, int a) { return i + j == a || i + k == a || i + l == a || j + k == a || j + l == a || k + l == a; } }