Commits

Shlomi Fish committed 933415f

Fix some bugs, but I'm still getting the wrong result.

  • Participants
  • Parent commits 6c54beb

Comments (0)

Files changed (2)

File project-euler/154/Makefile

-all: 154.exe 154.clang.exe
+all: 154.exe 154.clang.exe 154-debug.clang.exe
 
 154.exe: euler-154.c
 	gcc -std=gnu99 -O3 -Wall -fwhole-program -flto -fvisibility=hidden -fomit-frame-pointer -march=native -o $@ $<
 
 154.clang.exe: euler-154.c
 	clang -std=gnu99 -O3 -o $@ $<
+
+154-debug.clang.exe: euler-154.c
+	clang -g -std=gnu99 -o $@ $<

File project-euler/154/euler-154.c

 
 #define BASE 5
 
-unsigned char c5_counts[LIM+1];
+signed char c5_counts[LIM+1];
 
 int main()
 {
     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) ]
+     * of (200,000! / [ (x!) * (y=0)! * (z = 200,000-y-x)! ]
      *
      * */
     for(int x = 0; x <= LIM; x++)
         const int LIM_min_x = LIM - x;
         for (int y = 0; y <= LIM_min_x; y++)
         {
+#if 0
+            printf("y_c=%d\n", y_count);
+#endif
             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];
+            y_count += c5_counts[LIM_min_x-y]-c5_counts[y+1];
         }
 
         /*
          * As x -> x+1
          *
          * */
-        x_count += c5_counts[LIM_min_x-1]-c5_counts[x+1];
+        x_count += c5_counts[LIM_min_x]-c5_counts[x+1];
     }
 
     printf ("Result == %ld\n", result);