# Project Euler #19: Counting Sundays

# Project Euler #19: Counting Sundays

+ 2 comments I was stuck on this question for a while! For people who need some help, look into Zeller's Congruence :)

+ 2 comments Guys If you are using python, beware of using datetime module to solve this problem. Code will fail on test case 4th and beyond because datetime.date() function gives 'year is out of range error' on large values of year. and if year further exceeds 2^31 - 1, it gives 'python int too large to convert to C long' error.

+ 2 comments To all those who are failing TC 3 and 4, there are several reasons why this could be happening: 1. Make sure both result is calculated with both dates inclusive.

Make sure you cycle through months correctly. I suspect both these cases start from a date in December, so remember to loop correctly to January (depends entirely on your method of solving the problem.)

Trim the outputs correctly (Remove redundant whitespaces).

If you use the floor() function in C++, remember to handle Double --> Int or reverse conversions properly.

If you are using Zeller's Congruence method, ensure that you avoid negative modulus.

There should be no invalid date test cases as such, but if there are, handle appropriately by avoiding the invalid date, but still checking dates in between.

Remember to swap the dates if the second date is before the first date. Read the test cases properly, and you will notice the cases when this can occur.

If you solve all these issues, all test cases should pass.

+ 0 comments What's with 10^16 years? The universe will stop forming new stars after about 10^14 years. After that, things are going to get dark.

+ 1 comment OMGGGGGG

For Python (or not) people struggling with TC 3 & 4 ...

Use this test case :

1 4699 12 12 4710 1 1

You should end up with 18. I made 2 mistakes: - I was counting sundays for 2801 years instead of 2800 ... - I was inverting years after mod 2800, which completely broke things in some case where year1 was less than year2 but mod1 was more than mod2

Sort 59 Discussions, By:

Please Login in order to post a comment