16
3
Who doesn't like to chill on a Sunday morning in summer with a chilled beer and TV or in winter playing badminton or ultimate with friends?
I always think knowing how many days you have to chill in a month keeps you well-informed and helps you plan what you want to do. Be it sitting in front of your pc and solving a code-golf problem or going out to play football.
So, help me write a program or function which takes as input 2 positive integers, Y
and M
and outputs the number of Sundays in that particular year(Y
) and month(M
) (according to the Gregorian Calendar), followed by the date of each Sunday.
Also, do keep in mind that the shortest code wins.
Input Constraints
1000 <= Y <= 9999
1 <= M <= 12
Output
These test cases will have output will have the dates of each Sunday of that month in that year in the format DD-MM-YYYY
.
Sample Test Cases
Test Case 1
Sample Input
2017 1
Sample Output
5
01-01-2017
08-01-2017
15-01-2017
22-01-2017
29-01-2017
Test Case 2
Sample Input
2018 2
Sample Output
4
04-02-2018
11-02-2018
18-02-2018
25-02-2018
Test Case 3
Sample Input
2016 11
Sample Output
4
06-11-2016
13-11-2016
20-11-2016
27-11-2016
2I recommend allowing any date format, including a
Date()
object, and any output format, including[4, [<dateobj>, <dateobj>, <dateobj>, <dateobj>]]
(where<dateobj>
is an actual date object, and[]
is an actual array). – wizzwizz4 – 2017-04-09T09:33:34.770Wont that make it too easy? The least number of bytes can probably be achieved in PHP, regardless of format. I'm looking for the most clever solution in any other language (read: Python, Java, Scala, Perl, C++, JavaScript) – Koishore Roy – 2017-04-09T09:39:44.190
2When the output format is the defining part of a challenge, community consensus is that it's boring. In future I recommend using the Sandbox, but as nobody's answered yet you could get away with changing it. – wizzwizz4 – 2017-04-09T09:46:14.523
I'm new to making questions. Can you help me out here and change the question to make it better? @wizzwizz4 – Koishore Roy – 2017-04-09T09:57:00.537
1I'll make an edit. You can roll it back if you think it damages the challenge. – wizzwizz4 – 2017-04-09T10:01:20.223
I doubt it'll damage the challenge. Thanks for the help. :) – Koishore Roy – 2017-04-09T10:02:31.390
1So how flexible is the output format? For example, can it have
/
instead of-
? Or can it be month, then day, then year? – Luis Mendo – 2017-04-09T17:06:54.9971Any particular locale? Note that prior to 1582, the Julian calendar was in common use, with countries transitioning to Gregorian as late as 1952 for Greece. In England they jumped the calendar ahead 11 days in the month of September, 1752, leading to mass riots. Recommendation is to use something called the "Proleptic Gregorian Calendar" which pretends the current calendar was in use for as far back as you need. – None – 2017-04-09T19:01:38.867
Read the question. I've clearly mentioned Gregorian Calendar. Even the range of years is given – Koishore Roy – 2017-04-09T22:47:32.380
1Would you please answer my question (previous comment) about output format? In comments you seem to agree that the format is flexible, but the challenge doesn't clarify this – Luis Mendo – 2017-04-09T23:36:53.633
DD-MM-YYYY. Feel free to use ".", "-" or "/". – Koishore Roy – 2017-04-10T12:09:52.733
Thanks for answering. You should incorporate that into the challenge text. People are not expected to read the comments – Luis Mendo – 2017-04-10T22:01:33.647