Commits

committed 61614fe

Working solution. Yay!

The problem was that we should have checked for powers of 2 too.

project-euler/154/euler-154.c

` #define LIM 200000`
` `
` #define BASE 5`
`+#define BASE2 2`
` `
` signed char c5_counts[LIM+1];`
`+signed char c2_counts[LIM+1];`
` `
` int main()`
` {`
`             power *= BASE;`
`         }`
`     }`
`+    {`
`+        memset(c2_counts, '\0', sizeof(c2_counts));`
`+        int base = 1;`
`+        int power = BASE2;`
`+        while (power <= LIM)`
`+        {`
`+            for (int i = power; i <= LIM ; i += power)`
`+            {`
`+                c2_counts[i]++;`
`+            }`
`+            base++;`
`+            power *= BASE2;`
`+        }`
`+    }`
` `
`     long result = 0;`
`     int x_count = 0;`
`+    int x_count2 = 0;`
` `
`     /* At the beginning of the x loop, x_count is the 5-cardinality`
`      * of (200,000! / [ (x!) * (y=0)! * (z = 200,000-y-x)! ]`
`             printf("X=%d\n", x);`
`         }`
`         int y_count = x_count;`
`+        int y_count2 = x_count2;`
`         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)`
`+            if ((y_count >= 12) && (y_count2 >= 12))`
`             {`
`                 result++;`
`             }`
`-#if 0`
`-            printf("y_count=%d\n", y_count);`
`-#endif`
`             y_count += c5_counts[LIM_min_x-y]-c5_counts[y+1];`
`+            y_count2 += c2_counts[LIM_min_x-y]-c2_counts[y+1];`
`         }`
` `
`         /*`
`          *`
`          * */`
`         x_count += c5_counts[LIM_min_x]-c5_counts[x+1];`
`+        x_count2 += c2_counts[LIM_min_x]-c2_counts[x+1];`
`     }`
` `
`     printf ("Result == %ld\n", result);`
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.