Commits

Shlomi Fish committed cf04366

Program that gets stuck with gcc with opt flags.

  • Participants
  • Parent commits 872eaed

Comments (0)

Files changed (1)

project-euler/154/euler-154.c

     long result = 0;
     int x_count = 0;
 
+    /* At the beginning of the x loop, x_count is the 5-cardinality
+     * of (200,000! / [ (x!) * (y=0) * (z = 200,000-x) ]
+     *
+     * */
     for(int x = 0; x <= LIM; x++)
     {
         if (x % 1000 == 0)
         const int LIM_min_x = LIM - x;
         for (int y = 0; y <= LIM_min_x; y++)
         {
-            if ((y_count += c5_counts[LIM_min_x-y]-c5_counts[y]) >= 12)
+            if (y_count >= 12)
             {
                 result++;
             }
+#if 0
             printf("y_count=%d\n", y_count);
+#endif
+            y_count += c5_counts[LIM_min_x-y-1]-c5_counts[y+1];
         }
 
+        /*
+         * As x -> x+1
+         *
+         * */
         x_count += c5_counts[LIM_min_x-1]-c5_counts[x+1];
     }