Skip to main content
-11 bytes
Source Link
fireflame241
  • 16.3k
  • 2
  • 29
  • 72

Python 2, 109109 98 bytes

The datetime module docs are 50,000 bytes, so I'm not using the datetime module yet.

def f(d,m,y):t=~-m/2<1;yt=m<3;y-=t;Y=y%100;W=((d+(13*m+156*t-27)/5-y/100*2+y/400+Y+Y/4)%7+7)%7+1;print W,(d+6d+13-W)/7+17

Try it online!Try it online!

My formula to compute day of week comes from https://cs.uwaterloo.ca/~alopez-o/math-faq/node73.html.

The formula is as follows (converted from image to text):

W = (k + floor(2.6m-0.2) - 2C + Y + floor(Y/4) + floor(C/4)) mod 7

where floor(k) denotes the integer floor function

k is day (1 to 31)

m is month (1 = March, ..., 10 = December, 11 = Jan, 12 = Feb) Treat Jan & Feb as months of the preceding year C is century (1987 has C = 19)

Y is year (1987 has Y = 87 except Y = 86 for Jan & Feb)

W is week day (0 = Sunday, ..., 6 = Saturday)

Here the century and 400 year corrections are built into the formula. The floor(2.6*m-0.2) term relates to the repetitive pattern that the 30-day months show when March is taken as the first month.

The row number can be calculated as one more than the number of Sundays in the month preceding the day.

-7 bytes thanks to @GrzegorzOledzki

Python 2, 109 bytes

The datetime module docs are 50,000 bytes, so I'm not using the datetime module yet.

def f(d,m,y):t=~-m/2<1;y-=t;Y=y%100;W=((d+(13*m+156*t-27)/5-y/100*2+y/400+Y+Y/4)%7+7)%7+1;print W,(d+6-W)/7+1

Try it online!

My formula to compute day of week comes from https://cs.uwaterloo.ca/~alopez-o/math-faq/node73.html.

The formula is as follows (converted from image to text):

W = (k + floor(2.6m-0.2) - 2C + Y + floor(Y/4) + floor(C/4)) mod 7

where floor(k) denotes the integer floor function

k is day (1 to 31)

m is month (1 = March, ..., 10 = December, 11 = Jan, 12 = Feb) Treat Jan & Feb as months of the preceding year C is century (1987 has C = 19)

Y is year (1987 has Y = 87 except Y = 86 for Jan & Feb)

W is week day (0 = Sunday, ..., 6 = Saturday)

Here the century and 400 year corrections are built into the formula. The floor(2.6*m-0.2) term relates to the repetitive pattern that the 30-day months show when March is taken as the first month.

The row number can be calculated as one more than the number of Sundays in the month preceding the day.

Python 2, 109 98 bytes

The datetime module docs are 50,000 bytes, so I'm not using the datetime module yet.

def f(d,m,y):t=m<3;y-=t;Y=y%100;W=(d+(13*m+156*t-27)/5-y/100*2+y/400+Y+Y/4)%7+1;print W,(d+13-W)/7

Try it online!

My formula to compute day of week comes from https://cs.uwaterloo.ca/~alopez-o/math-faq/node73.html.

The formula is as follows (converted from image to text):

W = (k + floor(2.6m-0.2) - 2C + Y + floor(Y/4) + floor(C/4)) mod 7

where floor(k) denotes the integer floor function

k is day (1 to 31)

m is month (1 = March, ..., 10 = December, 11 = Jan, 12 = Feb) Treat Jan & Feb as months of the preceding year C is century (1987 has C = 19)

Y is year (1987 has Y = 87 except Y = 86 for Jan & Feb)

W is week day (0 = Sunday, ..., 6 = Saturday)

Here the century and 400 year corrections are built into the formula. The floor(2.6*m-0.2) term relates to the repetitive pattern that the 30-day months show when March is taken as the first month.

The row number can be calculated as one more than the number of Sundays in the month preceding the day.

-7 bytes thanks to @GrzegorzOledzki

Source Link
fireflame241
  • 16.3k
  • 2
  • 29
  • 72

Python 2, 109 bytes

The datetime module docs are 50,000 bytes, so I'm not using the datetime module yet.

def f(d,m,y):t=~-m/2<1;y-=t;Y=y%100;W=((d+(13*m+156*t-27)/5-y/100*2+y/400+Y+Y/4)%7+7)%7+1;print W,(d+6-W)/7+1

Try it online!

My formula to compute day of week comes from https://cs.uwaterloo.ca/~alopez-o/math-faq/node73.html.

The formula is as follows (converted from image to text):

W = (k + floor(2.6m-0.2) - 2C + Y + floor(Y/4) + floor(C/4)) mod 7

where floor(k) denotes the integer floor function

k is day (1 to 31)

m is month (1 = March, ..., 10 = December, 11 = Jan, 12 = Feb) Treat Jan & Feb as months of the preceding year C is century (1987 has C = 19)

Y is year (1987 has Y = 87 except Y = 86 for Jan & Feb)

W is week day (0 = Sunday, ..., 6 = Saturday)

Here the century and 400 year corrections are built into the formula. The floor(2.6*m-0.2) term relates to the repetitive pattern that the 30-day months show when March is taken as the first month.

The row number can be calculated as one more than the number of Sundays in the month preceding the day.