// generates answers for Quiz Wiz carts // #include "string.h" #include "stdio.h" int main() { //the cart wiring; every pin connects to pin 4 (high) or pin 5 (low) int cart[9]; //8 pins, but make it 1-indexed cart[4] = 1; //4 is tied high cart[5] = 0; //5 is grounded //the following cart[] assignments are all that need to be changed for new carts #if 1 //cart 1 (also QW Challenger cart C) //1+2+3+4, 5+6+7+8 cart[1] = cart[4]; cart[2] = cart[4]; cart[3] = cart[4]; cart[6] = cart[5]; cart[7] = cart[5]; cart[8] = cart[5]; #endif #if 0 //cart 3 //2+3+4+8, 1+5+6+7 cart[1] = cart[5]; cart[2] = cart[4]; cart[3] = cart[4]; cart[6] = cart[5]; cart[7] = cart[5]; cart[8] = cart[4]; #endif #if 0 //carts 4 and 10 //1+2+3+4+8, 5+6+7 cart[1] = cart[4]; cart[2] = cart[4]; cart[3] = cart[4]; cart[6] = cart[5]; cart[7] = cart[5]; cart[8] = cart[4]; #endif #if 0 //cart 5 //2+3+4+7+8, 1+5+6 cart[1] = cart[5]; cart[2] = cart[4]; cart[3] = cart[4]; cart[6] = cart[5]; cart[7] = cart[4]; cart[8] = cart[4]; #endif #if 0 //cart 6 //3+5+8, 1+2+4+6+7 cart[1] = cart[4]; cart[2] = cart[4]; cart[3] = cart[5]; cart[6] = cart[4]; cart[7] = cart[4]; cart[8] = cart[5]; #endif int buttons[10]; //0-9 buttons[0] = 0; buttons[6] = 1; //how the cart is wired to the buttons buttons[4] = cart[5]; buttons[5] = cart[4]; buttons[1] = cart[1]; buttons[2] = cart[6]; buttons[3] = cart[2]; buttons[7] = cart[3]; buttons[8] = cart[7]; buttons[9] = cart[8]; char digits[33]; for (int question = 1; question <= 1001; question++) { int numdigs = sprintf(digits, "%d", question); int latch1 = 0; int latch2 = 0; int latch3 = 0; int latch4 = 0; //process each button press for (int digitpos = 0; digitpos < numdigs; digitpos++) { char curdigit = digits[digitpos]; //how the buttons are connected to the latches if (curdigit == '1' || curdigit == '5' || curdigit == '8') latch1 = buttons[curdigit - '0']; else if (curdigit == '3' || curdigit == '0') latch2 = buttons[curdigit - '0']; else if (curdigit == '7' || curdigit == '4') latch3 = buttons[curdigit - '0']; else if (curdigit == '2' || curdigit == '6' || curdigit == '9') latch4 = buttons[curdigit - '0']; } int answer1, answer2; if (latch1 == latch2) answer1 = 0; else answer1 = 1; if (latch3 == latch4) answer2 = 0; else answer2 = 1; char answer; if ((answer1 == 0) && (answer2 == 0)) answer = 'D'; else if ((answer1 == 0) && (answer2 == 1)) answer = 'C'; else if ((answer1 == 1) && (answer2 == 0)) answer = 'B'; else if ((answer1 == 1) && (answer2 == 1)) answer = 'A'; printf("%d: %c\n", question, answer); } return 0; }