June 2020 is a month in which June 1st corresponds to Monday, June 2nd corresponds to Tuesday, ... June 7th corresponds to Sunday. For reference, here's the cal of June 2020.

      June 2020     
Su Mo Tu We Th Fr Sa
    1  2  3  4  5  6
 7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30            

Given a year and a month in the format [year, month], output two distinct values that tell whether this month starts on a Monday.

Test cases

[2020,6] -> True
[2021,2] -> True
[1929,4] -> True

[1969,1] -> False
[1997,5] -> False
[2060,1] -> False


  • The input can be in any format you prefer for your answer, e.g. numeric list, numeric tuple, etc. It doesn't have to be taken in this rigid format (it's JSON by the way).
  • However, making the input a Date object is a loophole here. You shouldn't make the input a Date object.
  • The month in the input doesn't have to be 1-indexed - it can also be 0-indexed.
  • You need to support all years after 1582 (the start of the Proleptic Gregorian calendar), up to the year 9999.
  • 7
    \$\begingroup\$ Is this asking, in less jargony terms, "does the given month start on a Monday"? The question is kind of hard to parse \$\endgroup\$ Jun 14, 2020 at 1:20
  • 17
    \$\begingroup\$ I suggest scrapping the entire challenge text and replacing it with: Given a year and a month, answer whether the given month begins with a Monday in the given year. \$\endgroup\$
    – Adám
    Jun 14, 2020 at 1:49
  • 2
    \$\begingroup\$ @MitchellSpector Unless anything specific is stated, you can assume that default I/O rules apply. (And the format used happens to be JSON, a very well-supported standard.) \$\endgroup\$
    – Adám
    Jun 14, 2020 at 2:15
  • 2
    \$\begingroup\$ I asked because the challenge specifically says "in the format [year, month]". That implies to me a rigid input format (how else would a rigid input format be expressed?). I agree with what I think is your implication that the challenge would be better with the usual default I/O rules. I think OP should clarify this. @Adám \$\endgroup\$ Jun 14, 2020 at 2:18
  • 4
    \$\begingroup\$ How large a year range do we have to support? For instance, certain hundred years skip the leap day, and year -1 coming directly before year 1 doesn't work well with some number types. \$\endgroup\$ Jun 14, 2020 at 12:22

35 Answers 35


Charcoal, 43 bytes


Try it online! Link is to verbose version of code. Takes 1-indexed month and outputs a Charcoal boolean, i.e. - for Monday, no output otherwise. Explanation:


Input the year and the month.


Decrement the year if the month is January or February.


Calculate the number of leap years and adjust for the month using a cyclic lookup table 403250351462, then output whether the result is zero (mod 7).


JavaScript, 45 bytes

n=>(''+new Date(n[0]+'-'+n[1]+'-01'))[0]=='M'

Takes input as an array like [2020, 6].

How it works

Converts the date object to a string then checks if the first character is an M.


Python 3, 76 68 bytes

Creates a new datetime object with given year and month (as a list) and the first day of the month and then checks if the day name starts with a M for Monday.

lambda l:date(*l,1).strftime("%A")[0]=="M"
from datetime import date

Try it online!


Python 3, 57 56 bytes

lambda y,m:date(y,m,1).weekday()<1
from datetime import*

Try it online!

  • 2
    \$\begingroup\$ You can save a byte by testing for weekday()<1. Also, the order of lines needs to be swapped or else there's no way to call the (anonymous) lambda: Try it online! \$\endgroup\$
    – Dingus
    Oct 6, 2021 at 5:23
  • \$\begingroup\$ Ok. One of the reasons I avoided changing the ==0 to <1 is because it is then identical to this answer. I'll swap the line order though. \$\endgroup\$ Oct 7, 2021 at 0:39
  • \$\begingroup\$ Posting identical answers is totally fine on our site, so you don't need to feel bad when your golf becomes identical to someone else's. \$\endgroup\$
    – Bubbler
    Oct 7, 2021 at 0:54
  • \$\begingroup\$ Thank you, I wasn't aware of that! I should probably fully read the rules. \$\endgroup\$ Oct 7, 2021 at 1:10

jq, 50 bytes


Try it online!

Not that short, but it's different enough that I thought it might be interesting enough to post...

It expects a year and a 0-indexed month as a list, meaning [2021,3] for April, 2021.

.+[1]+(               )                            - append "day 1" to input
       now|gmtime[3:8]                             - curr time breakout, drop Y/m/d fields
                       |mktime                     - convert to epoch time
                              |strftime("%w")=="1" - compare "day of week" to Monday

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy