diff --git a/p11.c b/p11.c index 88ed54b..9f27085 100644 --- a/p11.c +++ b/p11.c @@ -18,15 +18,15 @@ #define prd(x, y) (grid[y][x] * grid[y-1][x+1] * grid[y-2][x+2] * grid[y-3][x+3]) /* macro for checking all directions of a square x,y */ -#define check_square(x, y) \ - do { \ - if (x < 17) \ - setprod(px(x, y)); \ - if (y < 17) \ - setprod(py(x, y)); \ - if (x < 17 && y < 17) \ - setprod(pd(x, y)); \ - if (x >= 3 && y >= 3) \ +#define check_square(x, y) \ + do { \ + if (x < 17) \ + setprod(px(x, y)); \ + if (y < 17) \ + setprod(py(x, y)); \ + if (x < 17 && y < 17) \ + setprod(pd(x, y)); \ + if (x >= 3 && y >= 3) \ setprod(prd(x, y)); \ } while(0) diff --git a/p20.c b/p20.c new file mode 100644 index 0000000..21f2d4f --- /dev/null +++ b/p20.c @@ -0,0 +1,46 @@ + +/* + * http://projecteuler.net + * + * Projecteuler - Problem 20 + * ------------------------ + * 2010-05-17 Henrik Hautakoski + * + * easy with a good lib for doing arbitrary-precision arithmetic + */ + +#include +#include +#include + +char* fak(int n) { + + mpz_t v; + mpz_init(v); + mpz_fac_ui(v, n); + return mpz_get_str(NULL, 10, v); +} + +int sum(char *n) { + + int num = 0; + + for(; *n != '\0'; n++) + num += (*n) - 0x30; + + return num; +} + +int main() { + + char *n = fak(100); + + if (n == NULL) + return 1; + + printf("%i\n", sum(n)); + + free(n); + + return 0; +}