diff options
author | mjfernez <mjfernez@gmail.com> | 2020-03-06 18:55:37 -0500 |
---|---|---|
committer | mjfernez <mjfernez@gmail.com> | 2020-03-06 18:55:37 -0500 |
commit | 009ce017d99a8deb2089438381c273e8f3ea3b67 (patch) | |
tree | a2f19d4d25c87efa503166ab83e82e5259534b3b /19-Counting-Sundays | |
parent | 28d9d7226347e46527872d13671f316a1c943aed (diff) | |
download | Project_Euler_Solutions-009ce017d99a8deb2089438381c273e8f3ea3b67.tar.gz |
Added #19 Counting Sundays
Diffstat (limited to '19-Counting-Sundays')
-rwxr-xr-x | 19-Counting-Sundays/countsundays | bin | 0 -> 16776 bytes | |||
-rw-r--r-- | 19-Counting-Sundays/countsundays.c | 29 |
2 files changed, 29 insertions, 0 deletions
diff --git a/19-Counting-Sundays/countsundays b/19-Counting-Sundays/countsundays Binary files differnew file mode 100755 index 0000000..f5f9aa9 --- /dev/null +++ b/19-Counting-Sundays/countsundays diff --git a/19-Counting-Sundays/countsundays.c b/19-Counting-Sundays/countsundays.c new file mode 100644 index 0000000..e3f4d5a --- /dev/null +++ b/19-Counting-Sundays/countsundays.c @@ -0,0 +1,29 @@ +#include <stdio.h> +#include <time.h> + +// Implemented a timing routine for fun :) + +int main(){ + clock_t now, then; + int c = 0; + struct tm time = {0}; + + then = clock(); + time.tm_mday = 1; + + // Starting from 1-1-1901 + for(int y = 1; y <= 100; y++){ + for(int m = 0; m < 12; m++){ // Apparently January is the 0th month, + time.tm_mon = m; // even though there's no 0th day.... wtf K&R?? + time.tm_year = y; + time_t inttime = mktime(&time); + struct tm *t = localtime(&inttime); + if(t->tm_wday == 0) + c++; + } + } + printf("%d\n", c); + now = clock(); + printf("Only took %f ms\n", (double)(now - then) / (CLOCKS_PER_SEC / 1000)); + return 0; +} |