//------------------------------------------------------------------- // enigma1345.c (c) 2005 by Charles Petzold (www.charlespetzold.com) // // "Score? Date?" from New Scientist, 18 June 2005, page 54. // // The premise of this puzzle is too complex to be easily summarized. // It involves a grid showing the results of four "football" teams // playing each other. But the scores and dates of upcoming matches // are coded similarly. Determine which cells are scores. //------------------------------------------------------------------- #include int main(void) { // These variables represent the results of each match. // For example, AB is the result of team A playing B. // If AB is 0, the match was a draw. If AB is 1, then // A won, and if AB is 2, then B won. int AB, AC, AD, BC, BD, CD; // These variables represent end-of-season points for // each team. Each team gets 1 point for each draw and // 3 points for each win. int A, B, C, D; // Points can be easily calculated by indexing these // two arrays with the variables, AB, AC, etc. // Use Points1 for the first team in each pair and // Points2 for the second team. For example, for AB, // Points1[AB] is A's points for the match, and // Points2[AB] is B's points. int Points1[] = { 1, 3, 0 }; int Points2[] = { 1, 0, 3 }; // A total of 6 matches are played. Each team plays every // other team just once. These loops go through all the // possibilities. for (AB = 0; AB < 3; AB++) for (AC = 0; AC < 3; AC++) for (AD = 0; AD < 3; AD++) for (BC = 0; BC < 3; BC++) for (BD = 0; BD < 3; BD++) for (CD = 0; CD < 3; CD++) { // In the grid, C-D is the pair 3-4. That must // be a score because the equivalent date would // be 3 April, and we know the matches took // place in January to March. So, we only want // possibilities where CD equals 2 (ie, D won). if (CD != 2) continue; // For A-C, the grid shows 2-3, and for A-D the // grid shows 1-3. If those are both dates, the // dates are 1 March and 2 March, which would // means A would have to play two matches in a // row, which is disallowed. At least one of these // must be a score. Only consider cases where // AC or AD equals 2 (that is, A lost). if (AC != 2 && AD != 2) continue; // For both A-B and B-C, the grid shows 4-1. // They can't both be dates because that would // require B to play two matches on the same day. // Only consider cases when A beats B or B beats C. if (AB != 1 && BC != 1) continue; // Calculate the season-ending points. A = Points1[AB] + Points1[AC] + Points1[AD]; B = Points2[AB] + Points1[BC] + Points1[BD]; C = Points2[AC] + Points2[BC] + Points1[CD]; D = Points2[AD] + Points2[BD] + Points2[CD]; // We are told the total points of all teams is // odd. Only consider cases where the total is odd. if (((A + B + C + D) & 1) == 0) continue; // We are also told that one team accumulated // 5 points. Reject cases where noone has 5 points. if ((A != 5) && (B != 5) && (C != 5) && (D != 5)) continue; // Print out the results. printf ("AB=%i AC=%i AD=%i BC=%i BD=%i CD=%i\n", AB, AC,AD, BC, BD, CD); } } // The program does *not* take account of other criteria mentioned in the // problem: Because the teams take place at a specific time each day, // no team can play two matches the same day. The problem also states // that no team plays on two consecutive days. // // Without these criteria, the program prints the following three possibilities: // // AB=0 AC=0 AD=2 BC=1 BD=0 CD=2 // AB=0 AC=2 AD=0 BC=1 BD=0 CD=2 // AB=1 AC=2 AD-0 BC=0 BD=0 CD=2 // // There are no draws in the grid, so a value of zero in these results // indicates that the cell in the grid is a date. // // The third line implies that B-C and B-D are both dates, but if so, // they indicate consecutive days, which is not allowed. // // Therefore B-D is a date and A-B is a date. We already know that // C-D is a score. If A-B is a date then B-C must also be a score. // // Either A-C or A-D is a score, and the other is a date. Let's // reason it out. // // A-B is a date, and that date is 4 January, which means that this // particular grid was published on 3 January or earlier. Matches // B-C and C-D must have occurred on January 1, 2, or 3. Both // involve team C, so they can't be played on consecutive days. One // must have been played on the 1st and the other on the 3rd. But // B-C couldn't be played on the 3rd because B is playing A on the 4th. // Therefore, B-C occurred on 1 January and C-D on 3 January, and // A-B will occur on 4 January. // // If A-C is a score, the match must have been played during this period. // But it can't because then C would be playing twice the same day // or on consecutive days. // // Therefore A-D must be the score, and the match occurred on 1 January. // // The scores are A-D, B-C, C-D. //----------------------------------------------------------------------