// This program demonstrates three methods, each faster // than the last, for computing which scores are impossible // to get by throwing D darts at a dart board with W wedges. // The dart board is assumed to include rings for doubling // and tripling each throw. Depending on the values of the // macros below, the program will also allow throws of 0, // 25 and 50. // // You are free to use this code in any way you like. // // Ben Jackson, March 2010 #include #include // Set this to true to consider cases where darts // miss the board completely #define ALLOW_ZERO true // Set this to true to include the values 25 and 50, // like a regular dart board. #define USE_SPECIAL_VALUES true // Global Variables. // 'a' contains the valid throws up to the current number of darts. // 'b' is a scratch buffer swapped back and forth with 'a' bool* a; bool* b; // Functions. Defined and commented below. bool isValidThrow(int i, int w); void method1(int d, int w, int s=0); void method2(int d, int w, int s=0); void method3(int d, int w); int main(int argc, char** argv) { if (argc < 3) { printf("Specify two integers, d & w\n"); return 1; } int d = atoi(argv[1]); int w = atoi(argv[2]); int size = d*3*w + 1; a = new bool[size]; b = new bool[size]; // Erase a and b for (int x=0; x 2 for (int i=0; i<2*3*w; i++) { if (!a[i]) b[i+((d-2)*3*w)]=false; } // swap a&b bool* t = a; a = b; b = t; }