From 009ce017d99a8deb2089438381c273e8f3ea3b67 Mon Sep 17 00:00:00 2001 From: mjfernez Date: Fri, 6 Mar 2020 18:55:37 -0500 Subject: Added #19 Counting Sundays --- 01-Multiples-of-3-and-5/euler1 | Bin 02-Even-Fibonacci-numbers/fib | Bin 03-Largest-Prime-Factor/largestprime | Bin 04-Largest-Palindrome-Product/palindrome | Bin 05-Smallest-Multiple/smallmult | Bin 06-Sum-Square-Difference/sumsq | Bin 07-10001st-Prime/10001prime | Bin 08-Largest-Product-In-a-Series/productofdigits | Bin 09-Special-Pythagorean-Triplet/pyth | Bin 10-Summation-of-Primes/sumofprimes | Bin 11-Largest-Product-In-Grid/prodgrid | Bin 12-Highly-Divisible-Triangular-Number/bigfactors2 | Bin 13-Large-Sum/largesum | Bin 14-Longest-Collatz-Sequence/collatz | Bin 15-Lattice-Paths/lattice | Bin 16-Power-Digit-Sum/sumexp | Bin 17-Number-Letter-Counts/wordnums | Bin 19-Counting-Sundays/countsundays | Bin 0 -> 16776 bytes 19-Counting-Sundays/countsundays.c | 29 ++++++++++++++++++++++ 19 files changed, 29 insertions(+) mode change 100755 => 100644 01-Multiples-of-3-and-5/euler1 mode change 100755 => 100644 02-Even-Fibonacci-numbers/fib mode change 100755 => 100644 03-Largest-Prime-Factor/largestprime mode change 100755 => 100644 04-Largest-Palindrome-Product/palindrome mode change 100755 => 100644 05-Smallest-Multiple/smallmult mode change 100755 => 100644 06-Sum-Square-Difference/sumsq mode change 100755 => 100644 07-10001st-Prime/10001prime mode change 100755 => 100644 08-Largest-Product-In-a-Series/productofdigits mode change 100755 => 100644 09-Special-Pythagorean-Triplet/pyth mode change 100755 => 100644 10-Summation-of-Primes/sumofprimes mode change 100755 => 100644 11-Largest-Product-In-Grid/prodgrid mode change 100755 => 100644 12-Highly-Divisible-Triangular-Number/bigfactors2 mode change 100755 => 100644 13-Large-Sum/largesum mode change 100755 => 100644 14-Longest-Collatz-Sequence/collatz mode change 100755 => 100644 15-Lattice-Paths/lattice mode change 100755 => 100644 16-Power-Digit-Sum/sumexp mode change 100755 => 100644 17-Number-Letter-Counts/wordnums create mode 100755 19-Counting-Sundays/countsundays create mode 100644 19-Counting-Sundays/countsundays.c diff --git a/01-Multiples-of-3-and-5/euler1 b/01-Multiples-of-3-and-5/euler1 old mode 100755 new mode 100644 diff --git a/02-Even-Fibonacci-numbers/fib b/02-Even-Fibonacci-numbers/fib old mode 100755 new mode 100644 diff --git a/03-Largest-Prime-Factor/largestprime b/03-Largest-Prime-Factor/largestprime old mode 100755 new mode 100644 diff --git a/04-Largest-Palindrome-Product/palindrome b/04-Largest-Palindrome-Product/palindrome old mode 100755 new mode 100644 diff --git a/05-Smallest-Multiple/smallmult b/05-Smallest-Multiple/smallmult old mode 100755 new mode 100644 diff --git a/06-Sum-Square-Difference/sumsq b/06-Sum-Square-Difference/sumsq old mode 100755 new mode 100644 diff --git a/07-10001st-Prime/10001prime b/07-10001st-Prime/10001prime old mode 100755 new mode 100644 diff --git a/08-Largest-Product-In-a-Series/productofdigits b/08-Largest-Product-In-a-Series/productofdigits old mode 100755 new mode 100644 diff --git a/09-Special-Pythagorean-Triplet/pyth b/09-Special-Pythagorean-Triplet/pyth old mode 100755 new mode 100644 diff --git a/10-Summation-of-Primes/sumofprimes b/10-Summation-of-Primes/sumofprimes old mode 100755 new mode 100644 diff --git a/11-Largest-Product-In-Grid/prodgrid b/11-Largest-Product-In-Grid/prodgrid old mode 100755 new mode 100644 diff --git a/12-Highly-Divisible-Triangular-Number/bigfactors2 b/12-Highly-Divisible-Triangular-Number/bigfactors2 old mode 100755 new mode 100644 diff --git a/13-Large-Sum/largesum b/13-Large-Sum/largesum old mode 100755 new mode 100644 diff --git a/14-Longest-Collatz-Sequence/collatz b/14-Longest-Collatz-Sequence/collatz old mode 100755 new mode 100644 diff --git a/15-Lattice-Paths/lattice b/15-Lattice-Paths/lattice old mode 100755 new mode 100644 diff --git a/16-Power-Digit-Sum/sumexp b/16-Power-Digit-Sum/sumexp old mode 100755 new mode 100644 diff --git a/17-Number-Letter-Counts/wordnums b/17-Number-Letter-Counts/wordnums old mode 100755 new mode 100644 diff --git a/19-Counting-Sundays/countsundays b/19-Counting-Sundays/countsundays new file mode 100755 index 0000000..f5f9aa9 Binary files /dev/null and b/19-Counting-Sundays/countsundays differ 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 +#include + +// 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; +} -- cgit v1.2.3