#include #include #include /* aaron.c - tct - 3/18/15 This program outputs a list of expressions like '3+(1+3+6)', '3+(1+3-6)', '3+(1+3*6)', '3+(1+3/6)', '3+(1-3+6)', which may be evaluated via Perl or Javascript. The goal is to find which ones evaluate to 8. */ int main() { unsigned int i,j,k,m;char temp[15],wrk[15]; char op[]={'+','-','*','/'}; int idx[9][3]={ {1,4,6},{2,5,8},{2,4,7},{1,4,7},{1,3,5},{2,5,9}, {1,5,8},{1,4,7},{3,6,9} }; char *template[]={ "3o(1p3q6)","(3o1)p(3q6)","(3o1p3)q6","3o(1p3)q6","3o1p3q6", "(3o(1p3))q6","3o((1p3)q6)","3o(1p(3q6))","((3o1)p3)q6" }; printf("\naaron.c - tct - 3/18/2015\n\n"); for (m=0;m<9;m++) { strcpy(temp,template[m]); for (i=0;i<4;i++) { temp[idx[m][0]]=op[i]; for (j=0;j<4;j++) { temp[idx[m][1]]=op[j]; for (k=0;k<4;k++) { temp[idx[m][2]]=op[k]; strcpy(wrk,"'");strcat(wrk,temp);strcat(wrk,"',"); printf("%s\n",wrk); }}}} printf("\n");exit(0); }