//---------------------------------------------------------------------------------- // enigma1352.c (c) 2005 by Charles Petzold (www.charlespetzold.com) // // "Old MacDonald" by Adrian Somerfield, from New Scientist, 6 August 2005, page 50 // // Four varieties of potato: Primes, Queens, Roosters, and Superb. // // A one-stone (14-pound) bag of Chippers contains an integral number of pounds of // each of the four varieties in increasing weight: // // pc + qc + rc + sc = 14; // // pc < qc < rc < sc // // The variable pc (for example) is the number of pounds of Primes in the bag of Chippers. // // A one-stone bag of Boilers contains an integral number of pounds of each of the // four varieties in decreasing weight: // // pb + qb + rb + sb = 14; // // pb > qb > rb > sb // // Also, // // pc != pb // qc != qb // rc != rb // sc != sb // // Although that fact may help in working out the problem manually, it's not // required in the program shown below. // // A hundred-weight (8 stone) sack of Commercial consists of 1 stone bags // of Chippers and Boilers. Thus, // // c + b = 8 // // So, the total weight of Primes in this sack (the solution to the problem) // is: // // c * pc + b * pb // // We are also told: // // b * sb = c * sc // // c * qc + b * qb = c * rc + b * rb //----------------------------------------------------------------------------------- #include int main(void) { int pc, qc, rc, sc; int pb, qb, rb, sb; int c, b; for (pc = 1; pc < 3; pc++) for (qc = pc + 1; qc < 4; qc++) for (rc = qc + 1; rc < 6; rc++) { sc = 14 - pc - qc - rc; if (sc <= rc) continue; for (sb = 1; sb < 3; sb++) for (rb = sb + 1; rb < 4; rb++) for (qb = rb + 1; qb < 6; qb++) { pb = 14 - sb - rb - qb; if (pb <= qb) continue; for (c = 1; c < 8; c++) { b = 8 - c; if (c * sc != b * sb) continue; if (c * qc + b * qb != c * rc + b * rb) continue; printf("pc=%i qc=%i rc=%i sc=%i\n", pc, qc, rc, sc); printf("sb=%i rb=%i qb=%i pb=%i\n", sb, rb, qb, pb); printf("c=%i b=%i\n", c, b); printf("%i\n", c * pc + b * pb); } } } return 0; }